Forum Moderators: coopster
My script simply wants to re-name and upload a small PDF file to the server for storage. it then writes the user info and file name to a MySQL database for retrieval later.
In my error reporting I get a "File could not be uploaded because:
A system error occured."
But then the user info writes to the database (which it shouldn't if there is an upload error but that is a different problem and one I will tackle later).
I am using a slightly modified script that I use for image uploads aqll the time.
My upload directory name is set and it is writeable.
Thanks in advance.
R
$getExt = explode ('.', $file_name);
$file_ext = $getExt[count($getExt)-1];
if (empty($errors)) {
$allowed = array ('application/pdf');
if(in_array($_FILES['upload']['type'], $allowed)) {
$upload_dir = "resumes/";
$newname = $fname."_".$lname.".".$file_ext;
$filename = $upload_dir.$newname;
if(move_uploaded_file($_FILES['upload']['tmp_name'], $filename)) {
chmod($filename, 0644);
$content .="<p>Your resume was uploaded.</p>\n";
} else {
$content .='<p><font color="red">File could not be uploaded because:<b></p>';
switch ($_FILES['upload']['error']) {
case 1:
$content .='<p>The file exceedes the upload_max_filesize setting in php.ini.</p></font>';
break;
case 2:
$content .='<p>The file exceeded the MAX_FILE_SIZE setting in the HTML form.</p></font>';
break;
case 3:
$content .='<p>The file was only partially uploaded.</p></font>';
break;
case 4:
$content .='<p>No file was uploaded.</p></font>';
break;
case 6:
$content .='<p>No temporary folder available.</p></font>';
break;
default:
$content .='<p>A system error occured.</p></font>';
break;
} //end of Switch
}//end of if move uploaded file
}//end of Allowed
else {
$content .="We currently only allow PDF files for upload.";
}
The file size is small, The destination directory is writeable, My form encoding is "multipart/form-data.
Any suggestions as to where to look would be appreciated.
Russ
have you check your server error log for clues?
you might also compare your php.ini settings for "post_max_size" and "upload_max_size" with the actual file size.
I've tried the things you have suggested....even added 2 new error codes based in the error codes link that i didn't have, It still returns the default - a system error occured...
I can write a file to that directory via FTP, so I know it's there... and I can read it back out.
File size shouldn't be an issue, the test file is only 30k and I used to allow 10 Mb video uploads on this server.
Error log turned up nothing...
I'm at a loss...Maybe I'll re-write the script from scratch... or look elsewhere in the script...
Any other thoughts would be helpful, Thanks a bunch for the input you have given. I appreciate it.
[edit]I just realized now that my previous post was wrong, I meant open the file using the filename from $filename for writing - not reading[/edit]
The error that is reported is the "default" error from my script above - A value (1,2,3,4,6,7 or 8) is not passed. The default is just sort of a catch-all and, as a result, the least helpful of all the error messages I report.
Gergoe,
When the file is re-named, I use the First Name and the last name from my form, seperated by an underscore. (i.e. russ_kern.pdf) so is what you are asking is can php write that file name to the directory on the server?
I'm not sure how to do what you are describing with fopen. I've been learning php for a while, but haven't used that particular function yet.
One thing I can tell you, is that the correct $filename does get written to my database.
Sorry... think I'm showing a bit of my "green-ness" here.
Russ
echo '<pre>';
ini_set('display_errors', 1);
error_reporting(E_ALL);
echo "Dump the contents of \$_FILES\n";
var_dump($_FILES);
echo "Try to open target file for writing, and write 4 kb of data in it\n";
$h = fopen($filename, 'w');
if ($h!== false) {
var_dump(fwrite($h, str_repeat("TEST", 1024)));
fclose($h);
} else echo "Can not open {$filename} for writing\n";
echo "Try to move uploaded file to target\n";
var_dump(move_uploaded_file($_FILES['upload']['tmp_name'], $filename));
echo '</pre>';
This piece of code will in the first instance make sure you will see all runtime errors, then shows that the file has been successfully uploaded, the target file is writable (ever checked the permissions in that directory? The ftp user and the user running php is not the same, you might only ran into a permission issue) and the actual result of move_uploaded_file
Dump the contents of $_FILES
array(1) {
["upload"]=>
array(5) {
["name"]=>
string(11) "XOneXDA.pdf"
["type"]=>
string(15) "application/pdf"
["tmp_name"]=>
string(14) "/tmp/phpP3oMGP"
["error"]=>
int(0)
["size"]=>
int(38005)
}
}
Try to open target file for writing, and write 4 kb of data in it
Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid is 10006 is not allowed to access /var/www/vhosts/example.com/subdomains/dev/httpdocs/resumes owned by uid 0 in /var/www/vhosts/example.com/subdomains/dev/httpdocs/resume_upload.php on line 74
Warning: fopen(resumes/sss_sss.pdf) [function.fopen]: failed to open stream: No such file or directory in /var/www/vhosts/example.com/subdomains/dev/httpdocs/resume_upload.php on line 74
Can not open resumes/sss_sss.pdf for writing
Try to move uploaded file to target
Warning: move_uploaded_file() [function.move-uploaded-file]: SAFE MODE Restriction in effect. The script whose uid is 10006 is not allowed to access /var/www/vhosts/example.com/subdomains/dev/httpdocs/resumes owned by uid 0 in /var/www/vhosts/example.com/subdomains/dev/httpdocs/resume_upload.php on line 80
bool(false)
Warning: move_uploaded_file() [function.move-uploaded-file]: SAFE MODE Restriction in effect. The script whose uid is 10006 is not allowed to access /var/www/vhosts/example.com/subdomains/dev/httpdocs/resumes owned by uid 0 in /var/www/vhosts/example.com/subdomains/dev/httpdocs/resume_upload.php on line 84
Notice: Undefined variable: content in /var/www/vhosts/example.com/subdomains/dev/httpdocs/resume_upload.php on line 90
[edited by: eelixduppy at 9:00 pm (utc) on Dec. 11, 2007]
[edit reason] example.com [/edit]
A value (1,2,3,4,6,7 or 8) is not passed.
a value has certainly been passed.
you have only tested that it is not in that set of 8 integers.
is it 0?
greater than 8?
a negative number?
perhaps a floating point.
echo [php.net] is your friend here - you want to see the value of the error no matter what it is.
i'm still interested if you run out of other things to try...
I based this script off of an image upload script that lives in the domain itsself (www.mydomain.com/admin) and that script works fine... so maybe I should start looking at that...
Thanks for the help again...I learn a ton more from the things that don't go right than from the things that do. :) ...
Russ
As the error message states, the owner of the resumes directory (uid 0 - that's system I think?) is not the same as the user running the php process (probably that's your user). Try removing the directory with ftp, and creating it again, if that fails and you have SSH access, log in with SSH, and create the directory there. If you can not remove the directory (I'm not really good in *nix style permissions), then you may need contact support, or choose a different name for your directory.
You can read more about the behavior of php when set to work in safe_mode here: [php.net ].