PHP Image Upload using POST

非 Y 不嫁゛ 提交于 2019-12-13 20:04:40

问题


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. :)



来源:https://stackoverflow.com/questions/30542392/php-image-upload-using-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!