PHP文件上传错误tmp_name为空 [英] PHP file upload error tmp_name is empty
本文介绍了PHP文件上传错误tmp_name为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在文件上传中遇到此问题.在尝试验证TMP_NAME
为空时,我尝试上载我的PDF文件,而当我在$_FILES['document_attach']['error']
中进行检查时,该值是1,所以这意味着有错误.
I have this problem on my file upload. I try to upload my PDF file while checking on validation the TMP_NAME
is empty and when I check on $_FILES['document_attach']['error']
the value is 1 so meaning there's an error.
但是当我尝试上传其他PDF文件时,它已成功上传.为什么没有其他PDF文件?
But when I try to upload other PDF file it's successfully uploaded. Why is other PDF file not?
HTML
<form action="actions/upload_internal_audit.php" method="post" enctype="multipart/form-data">
<label>Title</label>
<span><input type="text" name="title" class="form-control" placeholder="Document Title"></span>
<label>File</label>
<span><input type="file" name="document_attach"></span><br>
<span><input type="submit" name="submit" value="Upload" class="btn btn-primary"></span>
</form>
PHP
if(isset($_POST['submit'])){
$title = $_POST['title'];
$filename = $_FILES['document_attach']['name'];
$target_dir = "../eqms_files/";
$maxSize = 5000000;
if(!empty($title)){
if(is_uploaded_file($_FILES['document_attach']['tmp_name'])){
if ($_FILES['document_attach']['size'] > $maxSize) {
echo "File must be: ' . $maxSize . '";
} else {
$result = move_uploaded_file($_FILES['document_attach']['tmp_name'], $target_dir . $filename);
mysqli_query($con, "INSERT into internal_audit (id, title, file) VALUES ('', '".$title."', '".$filename."')");
echo "Successfully Uploaded";
}
}else
echo "Error Uploading try again later";
}else
echo "Document Title is empty";
}
推荐答案
我只是检查phpinfo()中的最大大小;
I just check the max size in phpinfo();
然后检查是否已加载php.ini
Then check if php.ini is loaded
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
然后更改upload_max_filesize=2M to 8M
; Maximum allowed size for uploaded files.
upload_max_filesize = 8M
; Must be greater than or equal to upload_max_filesize
post_max_size = 8M
这篇关于PHP文件上传错误tmp_name为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文