tags:

views:

546

answers:

6
<form enctype="multipart/form-data">

<input type="file" name="mp3" />
<input type="submit" />
</form>

I tried the above,and found var_dump($_FILES); is always empty.

It only works when you upload text files or images.

UPDATE

I added method="POST" and it works.Why is POST necessary here?

+4  A: 

Did you specify the form method to be POST explicitly and try?

Adhip Gupta
Why is it necessary?
+1 I didn't know GET was the default method for forms when none was specified.
Pekka
Necessary because of what @Pekka just said. :)
Adhip Gupta
@Pekka's point is because of size limit of query string.But what if the file itself is very small?
I just added something on @Pekka's answer that might help!
Adhip Gupta
I guess maybe the exact reason why GET won't work is in how it's actually implemented.And I decided to take it as granted.
+5  A: 

MP3 file uploads should work like any other file upload, there's no discrimination by file type or extension.

Check whether your file is not larger than allowed.

PHP manual on file uploads

PHP manual on file uploads: Common pitfalls

Update: @Adhip Gupta solved it. GET seems to be the default method for a FORM, not POST as I thought. Check here: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.1

This attribute specifies which HTTP method will be used to submit the form data set. Possible (case-insensitive) values are "get" (the default) and "post". See the section on form submission for usage information.

Pekka
+1 I daresay an MP3 could easily be larger than the distribution php.ini `upload_max_filesize` and/or `post_max_size` vars.
Andy E
But the mp3 is not sent at all,I verified this in firebug.
Huh? That's strange. How large is it? Have you tried setting POST explicitly as Adhip Gupta suggests?
Pekka
It's actually caused by `POST`,why is it necessary?
See my updated answer. @Adhip Gupta nailed it.
Pekka
But why `GET` can't be used to upload files?
From the document I linked to: `With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.` with GET, all the data is put into the query string. You can't put a file in there, the size limit for the quesry string is 1024 bytes.
Pekka
I believe `GET` cannot be used to upload files as then the whole file will have to be passed as a query string parameter (which what `GET` really is). And, query strings have a relatively very small length limit.
Adhip Gupta
@pekka,so I should be able to submit a file with size 50 bytes via `GET`,right?
@user189729 I don't know for sure. Try it out!
Pekka
I just tried,no.So the reason should not be limit for query string.
Adhip Gupta
A: 

First thing to check is how big the files are, and what the max upload size in PHP.ini is set to.

ZombieSheep
A: 

Nothing wrong with your PHP code. And neither PHP nor the webserver know the difference between a MP3 file and other types of content.

Have you checked its not size related?

Do you know that there isn't other things between the browser and the PHP which might be filtering?

Have you tried using a wiretap (e.g. wireshark) to confirm the data is leaving the browser / getting to the server?

C.

symcbean
A: 

Maybe you have missed the MAX_FILE_SIZE which should be included.

<input type="hidden" name="MAX_FILE_SIZE" value="157286400" />

You should also add action="some.php" and method="POST" to <form>

Notinlist
A: 

OR using http://www.uploadify.com/ with ajax

TeknoSeyfo