开发者

i get error when i try to upload a file?

开发者 https://www.devze.com 2023-02-01 23:57 出处:网络
I keep gettingan error:Notice:Undefined index:on line 35 line 35: $handl开发者_运维知识库e = new Upload($_FILES[\'my_field\']);

I keep getting an error:Notice: Undefined index: on line 35

line 35:

 $handl开发者_运维知识库e = new Upload($_FILES['my_field']);

this is my input field

 <input type="file" size="32" name="my_field" value="" />

I do not understand this error, thanks!!!

EDIT:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post" action="actions/upload.php" />
 <p><input type="file" size="32" name="my_field" value="" /></p>
 <p class="button"><input type="hidden" name="action" value="image" />
 <br>
 <input style="margin-left:224px;" type="submit" name="submit" value="upload" />


Update: The OP is doing an Ajax request - well that obviously can't work with a File upload.

Old answer:

I think I found it.

Look closely at this tag:

 <form name="upload" id="upload" enctype="multipart/form-data" method="post"
 action="actions/upload.php" />

the closing /> closes the form. Everything that comes afterwards, is not inside that form - it's inside a new one that the browser probably generates to deal with the broken markup. That new form is not enctype=multipart/form-data.


Did you use enctype="multipart/form-data" on the form element?

This seems to be the only reason that the the key my_field isn't set on $_FILES.

Edit: If your file is bigger than post_max_size, you also get an empty $_FILES array.

See also: Apache/PHP: $_FILES Array mysteriously empty


In order to upload WITH an ajax submission you can use an IFRAME with the upload part in there.

  1. Send ajax form submission
  2. Using javascript trigger submit() on the upload form in the IFRAME
  3. Have the returning page in the iframe trigger a javascript complete response function in the main page

A bit complicated but would work. You would need some mechanism to tie them together, for instance if you are submiting info about the image, have step 1 return the id of the database row where that info is stored so that the IFRAME upload form can submit that id so it knows where to store the picture.

0

精彩评论

暂无评论...
验证码 换一张
取 消