View Single Post
  #1 (permalink)  
Old 01-14-04, 08:16 AM
therat's Avatar
therat therat is offline
Newbie Coder
 
Join Date: Jan 2004
Location: London
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Upload rename, resize & database insert

I need to be able to upload 2 files. The first has to be an image file and he second should be a zip/rar file. I have the following code, from here, that is uploading the files correctly.

PHP Code:

<?php


  $upload_dir 
$_SERVER['DOCUMENT_ROOT'] . "/uploads/"
    
// Get the upload file array 
    // and upload them to a destination 
    // by looping through that array 

    // An array of allowed file types 
    
$file_types = array(   
     
'image/pjpeg' => 'jpg',
     
'image/jpeg' => 'jpg',
     
'image/gif' => 'gif',
     
'image/x-png' => 'png',
     
'application/zip zip' => 'zip'
    
);

    
// Get the variables from previous form 
    
$up_files $_FILES['filename']; 

    
// set the while counter 
    
$counter 0
    
    
// Start the file upload to server 
    
while($counter <= count($up_files))  { 
         
        if(
$up_files['size'][$counter] > 0) { 
             
            
// Read the mime type of current file 
            
$filetype $up_files['type'][$counter]; 
            
$filename $up_files['name'][$counter]; 
            
$tempname $up_files['tmp_name'][$counter]; 
             
            if (!
array_key_exists($filetype$file_types))  { 
                 print 
"<font color='#990000'>File <b>$filename</b> 
of type <b>
$filetype</b> is not valid for upload!</font><br />"
            } else { 
                 
                
$upload_file $upload_dir $filename

                
// THIS UPLOADS THE FILE!!!! 
                
move_uploaded_file($tempname$upload_file); 
                 
                
// Print the uploaded file 
                //print "<font color='#009900'>File <b>$filename</b> uploaded... 
                //new location: <b>$upload_file</b></font><br />"; 
            

        } 
        
$counter++; 
    } 

//echo header ("Location: index.php");

?>
I now need to store the 2 filename in a database in the same row. I also want to rename the files so they have the same filename but keeping their original extensions. Is it possible to adapt this script, or is there anything else that can already do this sort of thing. I am fairly new to PHP but am willing to learn.
Reply With Quote