Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
927 views
in Technique[技术] by (71.8m points)

html - PHP file upload error tmp_name is empty

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.

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";

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just check the max size in phpinfo();

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';
}

Then Change the 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 

Finally reset your Apache Server to apply the changes

service apache2 restart

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...