0
votes

Things I have checked:

  • upload_max_filesize
  • file_uploads = On
  • directory's permissions are 777
  • checking the file actually uploads

Here's my html form:

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select a file to upload:
    <br>
    <input type="file" name="uploadFile" id="uploadFile">
    <br>
    <input type="submit" value="Upload Image" name="submit">
</form>

Here's a simplified of upload.php:

<?php
if ($_FILES['uploadFile']['error'] !== UPLOAD_ERR_OK) {
    die("Upload failed with error code " . $_FILES['file']['error']);
}
else {
    echo "Upload successful.<br>";
}

if (move_uploaded_file($_FILES["uploadFile"]["tmp_name"], "var/www/html/pictures/" . basename($_FILES["uploadFile"]["name"]))) {
    echo "The file ". basename( $_FILES["uploadFile"]["name"]). " has been uploaded.<br>";
}
else {
    echo "Error: ", PHP_EOL;
    print_r(error_get_last());
    exit;
}
?>

And here's the output I get:

Upload successful. Error: Array ( [type] => 2 [message] => move_uploaded_file(): Unable to move '/tmp/phpDelzbW' to 'var/www/html/pictures/archer.jpg' [file] => /var/www/html/upload.php [line] => 13 )

1

1 Answers

0
votes

now if you had just looked in the manual

UPLOAD_ERR_FORM_SIZE

Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.

you need to set the value of upload_max_filesize and post_max_size in your php.ini :

; Maximum allowed size for uploaded files.
upload_max_filesize = 99M

; Must be greater than or equal to upload_max_filesize
post_max_size = 99M