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" />
14
  • Can you show the full HTML form? Commented Jan 3, 2011 at 14:34
  • yeh let me update it thanks!! Commented Jan 3, 2011 at 14:35
  • Looks like the file isnt actually getting uploaded you should check to see if it uploaded successfully first is_uploaded_file($_FILES['my_filed']['tmp_name']) or isset($_FILES['my_field']) before acting on them Commented Jan 3, 2011 at 14:36
  • We need the entire HTML form and the library you are using. I am assuming that you are using one because of the Upload class. Commented Jan 3, 2011 at 14:37
  • 1
    You cant send files through ajax lol pekka beat me lol Commented Jan 3, 2011 at 14:51

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.