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.
- Send ajax form submission
- Using javascript trigger submit() on the upload form in the IFRAME
- 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.
精彩评论