1

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

line 35:

 $handle = 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" />
ajreal
  • 46,720
  • 11
  • 89
  • 119
getaway
  • 8,792
  • 22
  • 64
  • 94

3 Answers3

2

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

Thai
  • 10,746
  • 2
  • 45
  • 57
2

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • thats true it works, so how can i send a file thorough an ajax request!!! +1 from me ive seen examples of people uploading photos through jquery – getaway Jan 03 '11 at 14:57
0

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.

Patrick Evans
  • 41,991
  • 6
  • 74
  • 87