- Impact
- 4
Hi,
I'm working on a file upload for my site, and I'm having one problem with it.
The file that's going to be uploaded should be either .zip or .rar, and after the file is uploaded I need to run a query to add the information into a database.
The code I have is below:
$file_dir = "_______";
foreach($HTTP_POST_FILES as $file_name => $file_array){
if(is_uploaded_file($file_array['tmp_name'])){
$filename=$file_array['name'];
$id=(Some VALUE GOTTEN FROM A QUERY);
if(strstr($filename, "zip") || strstr($filename, "rar")){
if(strstr($filename, "zip"))
$id=$id.".zip";
if(strstr($filename, "rar"))
$id=$id.".rar";
// print "Filename= $id<br>";
move_uploaded_file($file_array['tmp_name'], $file_dir. $id) or die("couldnt copy");
// $filename=$file_array['name'];
$query="INSERT INTO somedatabase my information;
mysql_query($query) or die(mysql_errno().":".mysql_error());
print "Thank you for your submission! It will be reviewed shortly!";
}
else
print "please make sure the file type is .zip or .rar!";
}
else
print "ERROR!";
Now, the problem is that if the file is big and takes some time to upload, and user closes the browser or goes to another page or something of that nature, the file isn't uploaded, but the last query is still executed.
How can this be fixed?
Also, sometimes when I chose a rar file to upload, it says "please make sure the file is .zip or .rar" but when I select a different file that is .rar it works. (meaning it doesnt work for some but works for others)
And one last problem is that sometimes on .zip files or other extensions (ones that I do not allow, such as .exe) it prints "ERROR"
Can anyone please help me solve the above issues?
Thanks
I'm working on a file upload for my site, and I'm having one problem with it.
The file that's going to be uploaded should be either .zip or .rar, and after the file is uploaded I need to run a query to add the information into a database.
The code I have is below:
$file_dir = "_______";
foreach($HTTP_POST_FILES as $file_name => $file_array){
if(is_uploaded_file($file_array['tmp_name'])){
$filename=$file_array['name'];
$id=(Some VALUE GOTTEN FROM A QUERY);
if(strstr($filename, "zip") || strstr($filename, "rar")){
if(strstr($filename, "zip"))
$id=$id.".zip";
if(strstr($filename, "rar"))
$id=$id.".rar";
// print "Filename= $id<br>";
move_uploaded_file($file_array['tmp_name'], $file_dir. $id) or die("couldnt copy");
// $filename=$file_array['name'];
$query="INSERT INTO somedatabase my information;
mysql_query($query) or die(mysql_errno().":".mysql_error());
print "Thank you for your submission! It will be reviewed shortly!";
}
else
print "please make sure the file type is .zip or .rar!";
}
else
print "ERROR!";
Now, the problem is that if the file is big and takes some time to upload, and user closes the browser or goes to another page or something of that nature, the file isn't uploaded, but the last query is still executed.
How can this be fixed?
Also, sometimes when I chose a rar file to upload, it says "please make sure the file is .zip or .rar" but when I select a different file that is .rar it works. (meaning it doesnt work for some but works for others)
And one last problem is that sometimes on .zip files or other extensions (ones that I do not allow, such as .exe) it prints "ERROR"
Can anyone please help me solve the above issues?
Thanks














