views:

49

answers:

2

Hi folks,

I still have the problem with whitespaces:

I have an uploadform for users to upload mp3-files. It works fine, except when there are whitespaces in the filename. At the moment I tell the user not to use Filenames with whitespaces, but apparently its very common to use them in mp3s. So I would like to solve this problem. What happens is this:

Normally:

A user selects a file without whitespaces with an html file-input form:

<form method="post" enctype="multipart/form-data" name="form2" id="form2" action="' . $_SERVER[PHP_SELF] . '">
<input type="file" style="color:#888888" name="file" id="file" />

Then, on the serverside I handle the file with

copy($_FILES['file']['tmp_name'], $newfilename);

This works fine.

NOT normally:

A user selects a file with whitespace in the filename. The print_r($_POST) looks like this:

Array ( [x] => 21 [y] => 32 )

And the print_R($_FILES) looks like this:

Array ( [file] => Array ( [name] => 11. test with spaces.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ) )

As the tmp_name is empty, the script can't acess the file and there we have an ugly error... So what I think I need is to manipulate the [tmp_name], so that it has no whitespaces, because my Apache/Linux Server seems to have a problem with it. Has anyone any ideas how to solve this?

Greetz and Thanks

Maenny

A: 

Array ( [file] => Array ( [name] => 11. test with spaces.mp3 [type] => [tmp_name] => [error] => 1 [size] => 0 ) )

error code 1 means The uploaded file exceeds the upload_max_filesize directive in php.ini. Maybe here is your problem.

AurimasL
Man I feel stupid now - I had the POST_max_size right but the max_upload_size not. Could you tell me where you found the errorcode-definitions? thx
Maenny
You can find definitions on php.net website: http://php.net/manual/en/features.file-upload.errors.php
AurimasL
A: 

I strongly suggest not to use the real filename because if at any time you want to scale up you are going to have a lot of troubles, if you want to keep the original filename use an extra field for that. ;)

Hope this helps you.

Saikios
My fault, I didn't mention it - of yourse I rename the filename - thing is, when I have an $_FILES[tmp_name] that is empty because of the server not handling whitespaces, I can't even rename anything, let alone copy.
Maenny
it only happens with mp3 files with white spaces or with any file with whitespace? (have you checked what aurismasL said about the size?)
Saikios