Having trouble making a file host script.

Discussion in 'PHP' started by scottlpool2003, Oct 12, 2007.

  1. #1
    Hi guys. I'm trying to make a file upload script.

    It does work to a certain degree. A user uploads a file and it stores in a folder called /uploads/

    I need the script to then convert the uploaded file to a .zip and then give the user the download url.

    If you could tell me where I'm going wrong and give me the correct code, I will be very, very grateful!

    Here is the error I'm getting now:

    Fatal error: Class 'ZipArchive' not found in /home/fileflam/public_html/uploader.php on line 29

    The website is www.fileflamingo.com

    Thanks!

        <?PHP
    
    $target_path = "uploads/";
    
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    $_FILES['uploadedfile']['tmp_name'];  
    
    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
          // Create the md5 hash for naming purposes;
    
          $zipname = md5($somename_probably_user_provided);
    
           
     
          // create object
      
          $zip = new ZipArchive();
      
           
       
          // open archive
       
          if ($zip->open($zipname, ZIPARCHIVE::CREATE) !== TRUE) {
    
              die ("Could not open archive");
    
          }
     
    
          // list of files to add
    
          // list of files to add
    
          $fileList = array(
      
              'fstab2.php',
     
              'images/branch.gif',
     
              'files/php1.php'
    
          );
           
    
          // add files
         foreach ($fileList as $f) {
    
              $zip->addFile($f) or die ("ERROR: Could not add file: $f");   
    
          }
      
             
      
          // close and save archive
      
          $zip->close();
     
          echo "Archive created successfully.";   
     
          ?> 
    PHP:
     
    scottlpool2003, Oct 12, 2007 IP
  2. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    First error is here:

    
    $zip = new ZipArchive();
    
    PHP:
    This means that this extension for PHP is not installed
     
    Squash, Oct 12, 2007 IP
  3. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #3
    Do you mean on my server?
     
    scottlpool2003, Oct 12, 2007 IP
  4. Squash

    Squash Peon

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Of course :)
     
    Squash, Oct 12, 2007 IP