Current location: Hot Scripts Forums » Programming Languages » PHP » problem with multiple file upload and loop


problem with multiple file upload and loop

Reply
  #1 (permalink)  
Old 05-03-04, 04:29 PM
sita12691 sita12691 is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
problem with multiple file upload and loop

hello,

I had the form page set to 20 different userfiles with different names (userfile1, userfile2, etc). When I changed it to a loop, and changed the upload page to the one below, it stopped working correctly. It jumps right to the 'No File Uploaded' part of the first if statement, which I assume means it thinks the
file size is 0. I have no idea how to fix it, and all help would be greatly appreciated.

PHP Code:

<?php

for($c=1$c<=20$c++){
$file $HTTP_POST_FILES['userfile[$c]'];
if (
$file['size'] > 0) {

if (! 
is_uploaded_file($file['tmp_name'])) {
die(
'Not an authentic uploaded file.');
}

// the number of bytes to read from the file
$bytelen $file['size'];

// file pointer to the temporary location of th
// uploaded file
$fp fopen($file['tmp_name'], 'r');

// read in the file data and close the pointer
$data fread($fp$bytelen);
fclose($fp);

// massage the data for database insertion
$data addslashes($data);
$mime addslashes($file['type']);
$name addslashes($file['name']);

$file $_FILES['userfile[$c]']['name'];
$true checkext($file,"jpg");
echo(
"It returned '$true'");

if (
$true=='1'){

$uploaddir 'c:/program files/apache group/apache2/htdocs/uploadedpics/';
$uploadfile $uploaddir $HTTP_POST_FILES['userfile[$c]']['name'];

print 
"<pre>";
if (
move_uploaded_file($HTTP_POST_FILES['userfile[$c]']['tmp_name'], $uploadfile)) {
print 
"File is valid, and was successfully uploaded. ";
print 
"Here's some more debugging info:\n";
print_r($HTTP_POST_FILES);
echo 
$uploaddir;
echo 
$uploadfile;
} else {
print 
"Possible file upload attack! Here's some debugging info:\n";
print_r($HTTP_POST_FILES);
}
print 
"</pre>";
}
} else {

// no uploaded file, size was <= 0.
die('No file was uploaded.'); 
}

//Insert file info into table
$db mysql_connect("localhost""root");
mysql_select_db("evm",$db);
$sql "INSERT INTO filetable (file_name, file_mime, file_data) VALUES ('$name', '$mime', '$data')";
$result mysql_query($sql);}

function 
checkext($file,$search)
{
// Looks for $search at the end of the file
$lastpos strlen($file) - 1;
$diffrence strlen($search)-1;
$firstpos $lastpos $diffrence;
$z 0;
$x $firstpos;
while(
$z <= $diffrence)
{
if(
$file[$x] == $search[$z])
{
// Yes
$return 1;
}
else
{
// No!
$return 0;
}
$x++;
$z++;
}
return 
$return;
}

?>
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
New to perl, could use some help Arowana Perl 4 10-24-03 11:49 AM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM


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