views:

275

answers:

4

Hi folks,

I am building a site, where users can upload their mp3s and I ran into a little problem that I can't solve:

The upload works fine, but only when the user selects an mp3-file which has no spaces in their mp3-filename. A file like 'My nice mp3 file.mp3' will result in a NULL of $_FILES['file']. Has this to do with Server-configurations?

Anyone has an idea how to solve that? Other than telling the user just to upload mp3files without spaces in their names, that is :-)

Thanx,

Maenny

A: 

The filename of the remote (client) file should not affect how it is transported to the server. Are you sure that spaces are the problem?

nickf
Yes I am sure, see comment two answers later.
Maenny
A: 

Try to urlencode() your file name.

If that doesn't work, try rawurlencode().

If that doesn't work, I am off mark :)

ZZ Coder
I will try that, thanks for the advice
Maenny
Just to be sure: How exactly would you handle the encoding? That is, WHEN should I urlencode(). I have a form with a <input type"file" etc> and action="myscript.php". In the myscript.php I acess the $_FILES['file'] . Do I have to encode the $_FILES-var?
Maenny
This is probably not a PHP issue. Is this on Windows? There are known issues with certain versions of IE. If that's your problem, PHP doesn't even get the file.
ZZ Coder
Well yes, that seems to be the case. I used chrome and firefoy for testing, though...
Maenny
A: 

As the other users have said, it's probably not the spaces causing the problem. My first thought would be to check that your upload_limit for PHP is set high enough. Remember also that no matter what the user has called their file, you should NEVER store it with that filename on the server - there's too much risk of a potential security hole by doing that.

To diagnose this problem though, I'd suggest creating an MP3 file that you know is OK, make 2 copies - name one with spaces, and one without. And then see whether the one with spaces fails. If that is the case, then at least you know that you've definitely found the source of your problem - if not, then you've eliminated one possible cause of it, and you can look elsewhere.

Stephen Orr
Well I did exactly that - same file with spaces would not work, wothout works perfectly. And yes, I rename all the files uploaded to the server, but nevertheless, if I have a NULL as $_FILES['file'] I have nothing to rename... And I also set the upload_limit of PHP to the double of the filesize limit I allew in the script...
Maenny
Is the php.ini setting file_uploads set to On? I'm running out of possible reasons why this would be happening.
Stephen Orr
Yes of course, if not, the file_upload would not work at all, wouldn't it?
Maenny
Unknown. You'd get an error message, of that I'm sure. I don't know what else could be causing it though. Do you have some sample code I can look at?
Stephen Orr
A: 

Spaces should not cause this issue. I have an MP3 uploader on my website and have no trouble with spaces. I have tested with "Test Name.mp3" and it worked fine.

http://www.the-mag.me.uk/Music/Articles/Item/Add-Your-Music/

To help you diagnose any potential problem, try dumping out the contents of the $_FILES array and check to see if anything in there gives you a clue.

print_r($_FILES);
Sohnee
Well the result of print_r($_FILES) is NULL, but, as said only if there are spaces in the name.
Maenny