PHP Image Upload using POST

2019-08-07 01:03发布

问题:

I am trying to do a simple image uploader. I have searched for hours now and I made sure to set the enctype and I also changed my php.ini according to what I wanna do. The permissions of the files and folders are also correct. I've tried the exact same code on another webserver and it's working. I am running apache2 with php5 on a raspberry pi.

HTML Code

<form method="post" enctype="multipart/form-data" action="upload.php">
    <table>
        <tr><td><input type="file" name="uimage"></td></tr>
        <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
    </table>    
</form>

PHP Code

var_dump($_FILES);

The PHP Code returns an empty array. var_dump($_POST); works fine. On the other server both are working and the image uploads successfully. I assume it has to do with my server. I've checked the php.ini file and the 000-default in sites-enabled but really can not figure out what causes the issue.

This is what the error.log from apache2 says:

PHP Notice: Undefined index: uimage in /var/www/dmz/dotpic/upload.php on line 48, referer: http://localhost/upload.php

Edit:

By "POST" in the title of the question I mean the form method I am using. I am not trying to access the image using the $_POST array. Sorry for that.

回答1:

use $_FILES['uimage'] to access your file, $_POST does not work for files. more info use this link:http://www.w3schools.com/php/php_file_upload.asp



回答2:

You should not use $_POST to get files, you should use $_FILES['uimage'] to get the uploaded file.

$_FILES['uimage'] is an array with some information about size, temp name of the uploaded file, upload result and file type of the uploaded file.



回答3:

As what had been already answered above. You should use $_FILES['uimage'] and not $_POST['uimage']. Good Luck. :)