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 ;
}
?>