Upload file not working
Moderator: General Moderators
Upload file not working
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
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
Please send us your code
Re: Upload file not working
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.
Re: Upload file not working
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 :
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.
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>/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
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.
Re: Upload file not working
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
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
One question.
What should be the folder permissions ideally to make upload files work?
Thanks,
Sandeep
What should be the folder permissions ideally to make upload files work?
Thanks,
Sandeep
Re: Upload file not working
Try this in your if ($_FILES['f1']) part:
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.
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.'; }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.
Re: Upload file not working
Thanks for your feedback. I'll check.
Re: Upload file not working
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.