WEB kingtoad, baby caeks. come help me.

Discussion in 'OT Technology' started by drpepper, Nov 7, 2008.

  1. drpepper

    drpepper Active Member

    Joined:
    Nov 13, 2006
    Messages:
    38,076
    Likes Received:
    2
    Location:
    San Antonio
    you helped me with some code a while back using php pear and HTTP_Upload.
    it worked great. now i need you to help me yet again.

    your code:

    upload.php
    Code:
    <?php
    require_once('config.php');
    require_once('HTTP/Upload.php');
    
    $upload = new HTTP_Upload("en");
    $file = $upload->getFiles("f");
    
    if ($_POST['a'] == 'b') {
    
        $file->setValidExtensions($config['file_types'], 'accept');  
      
        if ($file->isMissing()) {
          print 'No file selected.  Please select a file to upload.';
        }
        
        if (!$file->isValid()) {
          print 'An error has occured.  Could not upload the file. '.$file->getMessage();
        }
        
        if ($file->isError()) {
          print $file->getMessage();
        }
        
        
        if ($file->isValid()) {
            $file->setName("safe");
            $extension =  strtolower($file->getProp("ext"));
            $original = $file->getProp("name");
    
            if (in_array($extension, $config['file_types'])) {
              if ($extension == 'bz2') {
                $filepath = $config['bz2'];
              }
              if ($extension == 'bsp') {
                $filepath = $config['bsp'];
              }
              
              if (!file_exists($filepath.$original)) {
                  $filename = $file->moveTo($filepath);
                  if (!PEAR::isError($filename)) {
                    header("Location: http://tf2maps.net/index.php?pageid=redirectupload");
            }
              } else {
                print 'The file exists already.  Please select a different file.';
              }  
            }
        }
        
    }
    
    ?>
    config.php
    Code:
    <?php
    
    /**
     * upload directories
     */
    $config['bz2'] = 'maps/'.$extension;
    /* $config['bsp'] = '...'.$extension; */
    /**
     * allowed extensions
     */
    $config['file_types']    = array('bsp', 'bz2');
     
    ?>
    
    and now i need a way to integrate an ftp upload based on the extension.

    Code:
    <?php
    
    if (isset($_POST['Submit'])) {
     if (!empty($_FILES['upload']['name'])) {
         $ch = curl_init();
         $localfile = $_FILES['upload']['tmp_name'];
         $fp = fopen($localfile, 'r');
         curl_setopt($ch, CURLOPT_URL, 'ftp://ftpaddresshere'.$_FILES['upload']['name']);
         curl_setopt($ch, CURLOPT_UPLOAD, 1);
         curl_setopt($ch, CURLOPT_INFILE, $fp);
         curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
         curl_exec ($ch);
         $error_no = curl_errno($ch);
         curl_close ($ch);
            if ($error_no == 0) {
                $error = 'File uploaded succesfully.';
            } else {
                $error = 'File upload error.';
            }
     } else {
            $error = 'Please select a file.';
     }
    }
    
    ?>
    
    i need for the .bz2 extension to upload they way it is now, but the .bsp extension to upload to an ftp address.
    any way to easy way to accomplish this?
     
  2. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,923
    Likes Received:
    11
    Location:
    Los Angeles
    Will take a look back at this later.
     
  3. drpepper

    drpepper Active Member

    Joined:
    Nov 13, 2006
    Messages:
    38,076
    Likes Received:
    2
    Location:
    San Antonio
    :love:
     
  4. drpepper

    drpepper Active Member

    Joined:
    Nov 13, 2006
    Messages:
    38,076
    Likes Received:
    2
    Location:
    San Antonio
    im noob but my thought was making that code a function, and then just adding that function to the .bsp extension :dunno:
     

Share This Page