开发者

php Form fileupload problem with whitespaces in filename

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 solv开发者_Python百科e 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜