I’m trying to upload a file to the apache public_html directory.
Well I believe it deserves to mention that I’m on a virtual hosting environment running on a VPS with a few domains and sub-domains.
Usually on my XAMPP server I wouldn’t have any problems loading files to temporary folder but on the new server It’s impossible it gives me an error when trying to upload.
I’ve checked the superglobal $_FILES and I get this error:
array(1) { ["file"]=> array(5) { ["name"]=> string(9) "test.gif" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(1) ["size"]=> int(0) } }
I’ve tried to set a tmp folder on the server with get_init(‘/tmp’) without any success.
Thank you very much for your kind attention.
Apparently I couldn’t set a new temporary folder for uploading files on my VPS.
What have I tried:
Set a new temporary folder with ini_set(‘upload_tmp_dir’, ‘/tmp’); without any success!
What was the reason for that? Answer: lack of permission.
So before using ini_set() make sure you have permissions to make it or else it will not affect the php engine behavior.
Anyway, it seems that if you don’t set a temporary folder, PHP will use /tmp by default.
In conclusion if you don’t set a new temporary folder won’t be a problem to upload files.
You probably have some other problem related with the size of the file. Check php info for file_uploads -> ON, upload_max_filesize, max_file_uploads and you can set a new temporary folder at upload_tmp_dir but won’t be a problem for sure.
If you still can’t upload files you probably are having some problem with library dependencies. My advise is make sure that all of the functions you’re using are installed on the server such as GD library particularly if you’re trying to manipulating images.
you can check php info by creating a new file with php extension and use between the php tags the function: phpinfo();
NOTE: you can make all of the above changes in php.ini or with the ini_set() function.
My server problem was the GD library!!!
There it goes my ten cents contribution.
I hope it helps someone 🙂