0

i get an image from a php form, but i don't recive all the information from the form. The code is below:

<form action="pages/post/upload.php" enctype='multipart/form-data' method="post">
    <input type="file" name="userfile" required/>
    <input type="submit" name="send" value="Invia"/>
</form>
<?php
$uploaddir = '/home/pino/Scrivania/Prova/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

print_r($_FILES['userfile']['name']);
print_r($uploadfile);
print_r($_FILES['userfile']['tmp_name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
{
    echo "File is valid, and was successfully uploaded.\n";
} 

else {
    echo "Possibile attacco tramite file upload!\n";
}

echo 'Alcune informazioni di debug:';
print_r($_FILES);

print "</pre>";

?>

When i print the content of the file with print_R($_FILES); i recive the follow:

Array
(
    [userfile] => Array
    (
        [name] => IMG_20170318_072135.jpg
        [type] => 
        [tmp_name] => 
        [error] => 1
        [size] => 0
    )

)

mastrobirraio
  • 135
  • 1
  • 9

2 Answers2

0

Your file has exceed the size limit (source:http://php.net/manual/en/features.file-upload.errors.php)

UPLOAD_ERR_INI_SIZE

Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

Community
  • 1
  • 1
Accountant م
  • 6,975
  • 3
  • 41
  • 61
0

Your array seems that your $_FILES return [error] => 1 so its related to file upload size.

  1. You need to check file upload size. Check file size with phpinfo().

  2. If upload_max_filesize less then your uploaded file size then change the file size to your image file size.

  3. If upload_max_filesize is proper then need to check post_max_size variable in php.ini file

For e.g:

upload_max_filesize = 7M

Note:

  • If you are working on localhost then php.ini file exist in wamp\bin\apache\apache2.4.9\bin.
  • Also, you can write phpinfo() in any of your php file and run it to check server configuration.
RJParikh
  • 4,096
  • 1
  • 19
  • 36