简体   繁体   中英

cant upload an image file

I have got this:

<input type="file" name="image">


 if(isset($_POST['submit'])) 

{

 if(isset($_FILES['image']['name']))
 {

     $image=$_FILES['image']['name'];
 }
 else
 {

    $error= 'Error: no image was set ';

 }

basically, it tells me that the image, name doesnt exist doesnt exist..why is that?

 {

    $error= 'Error: no image was set ';

 }

Does your FORM have an enctype="multipart/form-data" attribute?

<form name="xyz" action="myscript.php" enctype="multipart/form-data">
...
</form>

EncType attribute is used to tell the browser how to post the data to the server. If you don't use a multipart mime type, the data can't be sent to the server correctly.

Multipart looks like this:

boundary:xyz
====xyz====
name: field1
content-type: text/plain
content-lenght: 10
1234567890

====xyz====
name: field2
content-type: text/plain
content-lenght: 10
1234567890

====xyz====
name: field3
content-type: text/plain
content-lenght: 10
1234567890

You don't have to send it yourself, just set the enctype, and all that magic is done for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM