Thread: PHP Help!
View Single Post
Old 14-03-2005, 11:05   #1
Strzelecki
Inactive
 
Join Date: Jan 2004
Location: Essex
Age: 43
Services: 80/20Mbps FTTC on Freeola
Posts: 871
Strzelecki has reached the bronze age
Strzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze ageStrzelecki has reached the bronze age
PHP Help!

Ok, I'm in the process of creating a php script to upload multiple files, give them a unique id and store them on the server for download via WAP, hit a wall though in that for some reason I can't upload files over 10Kb in size, MAX_UPLOAD in php.ini is set to the default 8M (Scripts on i-web but working on it in uni) Apache timeout is 30s and uploads set to 2M, sorry for the sloppy code (some doesn't need to be there any more) but can anyone spot the problem?

PHP Code:
<?php
include 'config.php'; //load the standard variables


$num_files = count($_FILES['upfile']['name']); //same as above but for no files
if( $num_files < 1 ) 
{
   echo(
"Error! No files to upload... Exiting");  
   exit();
}

  for( 
$idx=0; $idx < $num_files; $idx++ ){ //loops upload code
    
    
$src = $_FILES['upfile']['tmp_name'][$idx]; //grabs array temp file name
    
$ext = strtolower(end(explode(".", $_FILES['upfile']['name'][$idx]))); //converts file name to lower case
    
$filnavn = $_FILES['upfile']['name'][$idx];        
    
$fileid = rand(10000, 99999); //creates a unique ID number for file,   
    //$fileid = substr(microtime() - time() * 2, 12); //another ID Creator method but zeros get clipped off(?) could cause problems. takes current time in millsecs, minus time in seconds to give last 4 millsec no's (take longer that a millsec to upload file and process, so should be unique)
    
$nytNavn = $fileid.".".$ext; //full file name (unique ID plus extension)
    
if(substr($fileid,5)== 0)
        
autom($wapurl,$urltoindex);

   
        
$dst = $_SERVER['DOCUMENT_ROOT']. '/prin/u1r08/wap/uploaded/' . $nytNavn; //set destination directory of file (to be changed to variable link to config.hphp)
    
        
copy($src, $dst);
        
clearstatcache();
        
usleep(500);
        
$fsize = filesize($dst);
        
        if((
$fsize >= $allowedsize) OR $ext=="php" OR $ext=="htm" OR $ext=="html") { //invalid uploads protection.
            
unlink("uploaded/$nytNavn");
            echo(
"<div align=center>File not uploaded, invalid file type.</div>");
        }
        else { 
//upload
            
            
$min = $timeallowed/60; //Time allowed to keep file.
            
$hours = $min/60;
            echo(
"<div align=center>".$_FILES['upfile']['name'][$idx]." upload success! Go to $wapurl using your mobile and enter this number: $fileid<br><br></div>");
            
                
//Insert uploaded file info into database.
    
    
             
$sql = ("INSERT INTO uploads(idnumber,filename,uptime) VALUES('$fileid','$nytNavn','".time()."')");
                
mysql_query($sql, $db);
            
        }
    }
            
        echo(
"<br><a href='$urltoindex/index.php'>Upload a new file</a>");
    
?>
The error that gets thrown is:
Quote:
Warning: filesize(): Stat failed for /var/www/htdocs/prin/u1r08/wap/uploaded/38170.jpg (errno=2 - No such file or directory) in /var/www/htdocs/prin/u1r08/wap/uploadfile.php on line 29
It's like it looping fast that the file is being stored or something?
Strzelecki is offline   Reply With Quote