PHP Form - File upload weirdness
I have never seen anything quite like this in my short career as a webmaster (2 years). I have written a program in php that allows user to enter grants into a repository. These grants can have files attached to them. All this is has been created and works fine (kind of...).
I have run into a strange problem with the file upload part of the form. The files will upload just fine 85% of the time (rough estimate). But occasionally the file will not be recognized at all. What I mean by "not recognized" is that on the backend page that does the work (moved the file over to correct directory, changes permissions, ect) the file isn't even there as if the form was blank. I'm very confused and I have never seen anything like this before. Since the code does work most of the time I'm sure that it is possible that it could be a problem with the files. However I have checked to make sure that file isn't corrupt and does contain data and that the file size is not extremely large (about 3-2mb). I have also run into this problem on different machines.
I have left out the code that I don't think is relevant, however I will add more if requested. All this seems to be pretty mundane stuff to me since I have done it before, that is why I'm at a loss to why it is not working every time.
I will reluctantly give the address of the site if requested, however it is a secure site and thus I will have to create a temp user/pass. I'm hoping that it doesn't come to that.
I'm hoping that a one of you web gurus might have an idea of what I might have done.
---------- CODE ------------------ [font end code]
....
... form ends ...
---------------------- [back end code] ------------------------
$file_1 = $_POST['file_1'];
...
if (is_uploaded_file($_FILES['file_2']['tmp_name']))
{ $size = $_FILES['file_2']['size'];
if ($size > $size_bytes)
{ echo "File Too Large. Please try again.";exit();}
$filename = $_FILES['file_2']['name'];
if(file_exists($upload_dir.$filename))
{ echo "Oops! The file named $filename already exists";exit();}
if (move_uploaded_file($_FILES['file_2']['tmp_name'],$upload_dir.$filename)) {
echo "File ($filename) uploaded!.";
chmod("$upload_dir$filename", 0744);
$strSQL = "insert into files (fname, grant_id, date) values ('$filename', $grant_id, '$date')";
$result=mysql_query($strSQL);
if ( !$result ){
echo "Error Writting to Database Webmaster";
}
}
else
{echo "There was a problem moving your file";exit();}
// successful upload of the file
$error_occured = "no";
}
else{echo "file_2 was not give a file";}
----------------------------------------------------------
Attachment | Size |
---|---|
modify.php.txt | 8.92 KB |
modify_backend.php.txt | 10.33 KB |
Busy posted this at 21:00 — 10th August 2005.
He has: 6,151 posts
Joined: May 2001
if the file name has spaces, symbols etc it can cause a problem
Is not the full code so am unsure if you are unlink()ing the image if error, maybe your temp folder is getting to big
unrelated to problem - Your error message link would cause a 404
yktan posted this at 01:44 — 11th August 2005.
They have: 3 posts
Joined: Aug 2005
Could it be because the file is larger than the size you set in php.ini? Easiest way is look for any error log files that are created by php in the script directory.
Do you like games? Come visit us at Complete Gaming Directory
r3a1 posted this at 18:55 — 18th August 2005.
He has: 28 posts
Joined: Aug 2005
It was in the php.ini file ... I had to track down the sys admin and that was the problem. Thanks for your help.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.