gpt4 book ai didi

PHP文件上传报错tmp_name为空

转载 作者:IT王子 更新时间:2023-10-29 00:07:03 26 4
gpt4 key购买 nike

我在上传文件时遇到了这个问题。我尝试上传我的 PDF 文件,同时检查验证 TMP_NAME 是否为空,当我检查 $_FILES['document_attach']['error'] 时,值为 1所以意味着有错误。

但是当我尝试上传其他 PDF 文件时,它已成功上传。为什么其他PDF文件不是?

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() 中的最大大小;

然后检查php.ini是否加载

$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改为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

最后重置您的 Apache 服务器以应用更改

service apache2 restart

关于PHP文件上传报错tmp_name为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30358737/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com