views:

213

answers:

1

Hey,

I'm working on a upload script and using move_uploaded_file() function. The problem is, that it only works for .txt, .jpg, .psd and some other file types I've tryed, but not for .mp3, .mov, .avi and maybe others.

There is nothing to the script, it's just the function. An interesting thing is, that it doesn't show any error msgs, it just doesn't upload the file.

Does anybody have some experience with this problem?

Thanks, Mike.

+5  A: 

I don't think this is actually down to file type, more to file size.

Create a PHP script that runs a <? phpinfo(); ?> and look out for the upload_max_filesize setting. It could be that it is something like 8 MB, causing all larger file uploads to fail.

If that is the case, you can try changing the setting using ini_set("upload_max_filesize", "3200000000"); for example. In most cases, if on a shared hosting package, that will probably not work, though. You may have to contact your hosting provider then.

You should also make your script throw reliable error messages. The attempt to upload a file that is too big usually shows up as an error when uploading the file. Check the Error Messages Explained chapter in the manual for the respective error codes and their meanings.

Pekka
You were right, thanks. It is set to 2MB limit. Don't you know how to change it btw?
Mike
@Mike what kind of hosting are you on? Own server, shared hosting?
Pekka
Localhost (wamp)
Mike
Either edit your `php.ini` or use function `ini_set` mentioned above. You may also have to change value of `post_max_size` to be at least equal to the max upload file size
dev-null-dweller
tryed the ini_set function and it does nothing =/
Mike
@Mike then edit your `php.ini`. Don't forget to restart the server.
Pekka
edited php.ini upload_max_filesize = 2M to 20M and nothing heppened after the restart
Mike
@Mike Can you check `phpinfo()` again whether the value has changed`? If it hasn't, you made the change in the wrong `php.ini`. Check the phpinfo() output to see which php.ini is used (it's in the top section.) On a wamp install, you usually have at least 2 - one in the Windows directory, one in the php binary directory.
Pekka
Ok, changed the upload_max_filesize, but I'm still not able to upload =/
Mike
@Mike Strange. There's another option in php.ini to check: `post_max_size`, see http://de.php.net/manual/en/ini.core.php#ini.post-max-size If changing that doesn't help (don't forget to restart the server), then you'll have to check what `$_FILES[xyz]["error"]` contains. Try `print_r($_FILES);` in the receiving script and see what the error code is. Compare it to the list I linked to in my answer. I'm calling it a day now, good luck!
Pekka
+1 freakout to Pekka for doing realtime tech support in the comments section!
Andrew Heath
ok, I figgured out, that you also have to chage the 'post_max_size', then it works. ;-)
Mike