Upload file not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandeept
Forum Newbie
Posts: 15
Joined: Wed Sep 10, 2008 2:15 am

Upload file not working

Post 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
eskio
Forum Commoner
Posts: 66
Joined: Tue Apr 01, 2008 1:00 am

Re: Upload file not working

Post by eskio »

Please send us your code
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Upload file not working

Post by s.dot »

Please show us the code and inform us what error code 7 means.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sandeept
Forum Newbie
Posts: 15
Joined: Wed Sep 10, 2008 2:15 am

Re: Upload file not working

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Upload file not working

Post 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!'; }
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sandeept
Forum Newbie
Posts: 15
Joined: Wed Sep 10, 2008 2:15 am

Re: Upload file not working

Post 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
sandeept
Forum Newbie
Posts: 15
Joined: Wed Sep 10, 2008 2:15 am

Re: Upload file not working

Post by sandeept »

One question.

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

Thanks,
Sandeep
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Upload file not working

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sandeept
Forum Newbie
Posts: 15
Joined: Wed Sep 10, 2008 2:15 am

Re: Upload file not working

Post by sandeept »

Thanks for your feedback. I'll check.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Upload file not working

Post by s.dot »

If upload_tmp_dir is not writable, php will use the system default, which is /tmp on most servers.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply