Unable to Upload Image to Server ios

天大地大妈咪最大 提交于 2019-12-04 13:45:11

When you upload image data as multipart, it end up in $_FILES. Since PHP 4.3.0, $_REQUEST no longer contains any information about files uploaded in this manner.

The rest of your code is based around the idea of the image not being uploaded as multipart but instead being uploaded as a base-64 string in a standard form. Instead of writing base 64 data to a file, you will simply need to get the information about the file from $_FILES and move it to your target directory with move_uploaded_file.

From the comments, that print_r is returning:

Array ( 
    [files] => Array ( 
        [name] => iphone.jpg 
        [type] => application/octet-stream 
        [tmp_name] => /Applications/XAMPP/xamppfiles/temp/php4VsKOv 
        [error] => 0 
        [size] => 13484 
    )
) 

Meanwhile, your code is doing this:

$Image = $_FILES['files']['name'];
print_r($_FILES);
foreach ($Image as $f => $name) {

You're treating $_FILES['files']['name'] as if it's an array, when it isn't. That's why PHP says "Invalid argument supplied for foreach()"

Please note that it can become an array if multiple files are uploaded with the same form element name. This is by far the most infuriating thing about $_FILES.

Your uploading code does not attempt to use the PHP syntax needed to upload multiple files at once, so your PHP code does not need to worry about the content of the inner array being arrays themselves. You can eliminate the foreach loop and all references to the [$f] index.

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