Page 1 of 1

Upload file not working

Posted: Mon Feb 18, 2013 4:23 am
by sandeept
Hi,

I have created a simple script to upload file. It's not working. Shows error code 7.

I am running the script on CentOS. I have given full permissions (777) on upload temporary, final folders, even on the script file.

Temporary upload folder set through php.ini

Script has all required parameters like enctype="multipart/form-data" etc.

Please help.

Thanks,
Sandeep

Re: Upload file not working

Posted: Mon Feb 18, 2013 5:11 am
by eskio
Please send us your code

Re: Upload file not working

Posted: Mon Feb 18, 2013 5:16 am
by s.dot
Please show us the code and inform us what error code 7 means.

Re: Upload file not working

Posted: Mon Feb 18, 2013 7:39 am
by sandeept
Error 7 is,

UPLOAD_ERR_CANT_WRITE
Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

I have PHP 5.3 on server.

Code :

Code: Select all

<?php

if($_FILES["f1"]){

	echo ini_get("upload_tmp_dir")."<br />";
	print_r($_FILES);
	exit();

}

?>
<br /><br />
<form enctype="multipart/form-data" method="post" action="index.php">
	<input type="file" name="f1" /><br />
	<input type="submit" />
</form>
When I try to upload any file, it prints this :

/var/www/html
Array ( [f1] => Array ( [name] => New Text Document.txt [type] => [tmp_name] => [error] => 7 [size] => 0 ) )

I printed "upload_tmp_dir" value to see if the script is picking it up from php.ini
This contstant was set blank by default. I have set 777 permissions on /var/www/html

Thanks,
Sandeep

s.dot| - Moderator Edit - Please use formatting tags when posting code in the forums.

Re: Upload file not working

Posted: Mon Feb 18, 2013 7:52 am
by s.dot
Try seeing if it is writable.

Code: Select all

if (is_writable(ini_get('upload_tmp_dir')){ echo 'writable!'; } else { echo 'not writable!'; }

Re: Upload file not working

Posted: Mon Feb 18, 2013 9:35 am
by sandeept
Sorry about the code problem. I'll be careful now on.

It was not writable. I gave 777 permissions on it to test the script. But, still I get the same output.
Please advise.

Thanks,
Sandeep

Re: Upload file not working

Posted: Mon Feb 18, 2013 10:50 am
by sandeept
One question.

What should be the folder permissions ideally to make upload files work?

Thanks,
Sandeep

Re: Upload file not working

Posted: Mon Feb 18, 2013 11:14 am
by s.dot
Try this in your if ($_FILES['f1']) part:

Code: Select all

if (is_writable(ini_get('upload_tmp_dir')){ echo 'writable!'; } else { echo 'not writable, attempting to make writable.';  if (chmod(ini_get('upload_tmp_dir'), 0777){ echo ' .. success'; } else { echo, ' .. failure, could not make writable.'; }
Ideally the web server should own php and only 0644 permissions be needed. However, if the web server does not own php then 0777 permissions will be needed.

Re: Upload file not working

Posted: Mon Feb 18, 2013 9:46 pm
by sandeept
Thanks for your feedback. I'll check.

Re: Upload file not working

Posted: Tue Feb 19, 2013 5:29 am
by s.dot
If upload_tmp_dir is not writable, php will use the system default, which is /tmp on most servers.