PHP & FTP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Smurf
    New Member
    • Jul 2007
    • 2

    PHP & FTP

    Hi everyone,

    I am pulling my hair out here. I have been trying to make a simple upload script for friends and family to upload files to share with each other. The idea is to upload zip files with pics in them. I have been trying to get this to work and seem to be struggling. This is what i have tried so far which I found on another site.

    Code:
    <?php
    $target = "MYROOTGOESHERE/uploads/incoming/"; 
    $target = $target . basename( $_FILES['uploaded']['name']) ; 
    $ok=1; 
    
    //This is our size condition 
    if ($uploaded_size > 50000000) 
    { 
    echo "Your file is too large.  Its a maximum of 50Mb<br>"; 
    $ok=0; 
    } 
    
    //This is our limit file type condition 
    if ($uploaded_type =="text/zip") 
    { 
    echo "No PHP files<br>"; 
    $ok=0; 
    } 
    
    //This is our limit file type condition 
    //if (!($uploaded_type=="application/zip")) {
    //echo "You may only upload ZIP.<br>";
    //$ok=0;
    //} 
    
    if ($ok==0) 
    { 
    Echo "Sorry your file was not uploaded"; 
    } 
    else
    {
      if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
      {
      echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
      } 
      else {
      echo "Sorry, there was a problem uploading your file.";
      }
    }
    ?>
    This seems to work a treat however my webhost has the upload_max_file size and the post_max_size set to the default of 8M/2M. I have tried the ini_set procedure to increase these to 50M without any success. The file i wanna upload is 41Mb which obviosuly fails.

    So, I noticed the FTP function. My first question here is does this function rely on these two php.ini variables ?

    The next thing is, i cannot seem to get it to work. I have search the other posts in this forum and googled it and cannot seem to get it working.

    Here is what i have been trying;

    Code:
    <?php
    $local_file = 'c:\TB.log';  //its my understanding that this is the file on my PC
    $remote_file = 'tb.log';  //its my understanding that this is the destination, i.e. file to save it to on the ftp server
    
    $ftp_server= 'myftpserver';
    $ftp_user_name = 'theusername';
    $ftp_user_pass = 'thepassword';
    
    // set up basic connection
    $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to".$ftp_server);
    
    
    // login with username and password
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass) or die("Couldn't Login to FTP Server");
    
    //ftp_pasv($conn_id, true); //you can comment or uncomment it if you using firewall
    //echo "ftp pasv is on";
    
    // upload a file
    if (ftp_put($conn_id, $remote_file, $local_file, FTP_ASCII)) {
     echo "successfully uploaded $file\n";
    } else {
     echo "There was a problem while uploading $file\n";
    }
    
    // close the connection
    ftp_close($conn_id);
    ?>
    I don't know if it makes any difference but i am trying this to the same server, i.e. its hosting my ftp and also my php/website.

    All i seem to get is "There was a problem while uploading TB.log". Its really doin' mi head in so any help would be really appreciated.

    Thanks

    Wayne
  • eragon
    Contributor
    • Mar 2007
    • 431

    #2
    if your using a free server or a basic server the company may heve a permanant upload size that applies to all files goung onto the server. Can you upload this zip through ftp without php or using a file manager from your server company?

    Comment

    Working...