PHP image upload using POST

I am trying to make a simple image loader. I have searched for hours and I made sure to set the enctype and I also changed my php.ini to match what I want to do. The file and folder permissions are also correct. I tried the same code on another webserver and it works. I am running apache2 with php5 on 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);

      

PHP code returns an empty array. var_dump($_POST);

works fine. On the other server both are running and the image upload is successful. I am assuming it is related to my server. I checked the php.ini and 000-default file in the allowed sites, but really can't figure out what is causing the problem.

This is what the error.log from apache2 says:

PHP note: Undefined index: uimage in /var/www/dmz/dotpic/upload.php on line 48, referent: 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 an array $_POST

. Sorry for this.

+1


source to share


3 answers


use $_FILES['uimage']

to access your file, $ _POST doesn't work for files. more details about this link: http://www.w3schools.com/php/php_file_upload.asp



+1


source


You shouldn't use $_POST

to get the files, you must use $_FILES['uimage']

to get the downloaded file.



$_FILES['uimage']

is an array with some information about the size, the temporary name of the uploaded file, the results of the upload, and the file type of the uploaded file.

0


source


As mentioned above. You must use $ _FILES ['uimage'] and not $ _POST ['uimage']. Good luck. :)

0


source







All Articles