Jay Viluan Jay Viluan - 1 year ago 133
HTML Question

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 its successfully uploaded. Why other PDF file is not?


<form action="actions/upload_internal_audit.php" method="post" enctype="multipart/form-data">
<span><input type="text" name="title" class="form-control" placeholder="Document Title"></span>
<span><input type="file" name="document_attach"></span><br>
<span><input type="submit" name="submit" value="Upload" class="btn btn-primary"></span>



$title = $_POST['title'];
$filename = $_FILES['document_attach']['name'];
$target_dir = "../eqms_files/";
$maxSize = 5000000;


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";
echo "Error Uploading try again later";

echo "Document Title is empty";


Answer Source

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 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download