Current location: Hot Scripts Forums » Programming Languages » PHP » file upload


file upload

Reply
  #1 (permalink)  
Old 06-16-04, 03:23 PM
csmaster2005 csmaster2005 is offline
Newbie Coder
 
Join Date: Feb 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
file upload

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 06-16-04, 07:57 PM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
I didn't notice a filesize check, php has a filesize limit and you can also set it using MAXFILESIZE in a hidden input field. You can also set the timeout for you php script to upload.

Also another way to insure file upload is to open a new window and do the upload in that window with information telling the use what is going on via javascript or php.

You insertion problem can be solved by doing the following,

PHP Code:

<?php

if(move_uploaded_file($file_array['tmp_name'], $file_dir$id)){
// $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!";
 }
?>
__________________
Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel document containing records, need to save as a text file to upload to mysql bearslife PHP 1 06-05-04 04:24 AM
Image Upload, File Type Check, File Size Check CarBoffin PHP 3 04-13-04 03:26 PM
If statement in file upload mdhall PHP 4 04-12-04 06:33 PM
Upload Script Problem!!! seanknighton Perl 0 03-21-04 10:54 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM


All times are GMT -5. The time now is 09:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.