FTP in PHP error

Discussion in 'Software' started by man_im_bored, Aug 23, 2005.

  1. man_im_bored

    man_im_bored Private E-2

    Hi everybody

    (hi doctor Nick)

    I am stumped at the moment over this php / ftp error.

    Code:
    $ftp_server= "www.myserver.com";//serverip
       $conn_id = ftp_connect($ftp_server); 
       
      
       // login with username and password
       $user = "username";
       $passwd = "******";
       $login_result = ftp_login($conn_id, $user, $passwd); 
    
    // check connection
    
      if ((!$conn_id) || (!$login_result)) { 
           echo "FTP connection has failed!";
           echo "Attempted to connect to $ftp_server for user $user"; 
           die(); 
       }
    
     ftp_chdir($conn_id, "public_html");
     ftp_chdir($conn_id, "forms");
    
    // upload the file
    
    $upload = ftp_put($conn_id, $_FILES['FormFile']['name'], $_FILES['FormFile']['tmp_name'], FTP_BINARY); 
    
    // check upload status
    
    if (!$upload) { 
           echo "FTP upload has failed!";
       } 
    
    // close the FTP stream 
    
    ftp_close($conn_id); 
    
    
    Basically, the point of the script, is to upload a file from your machine to a webserver (not the same server that the script is running off, hence why it is ftp instead of move_uploaded_file() etc).

    The problem i get is that, there is no php error. But when it gets to the server, it reads 0kb. This script use to work, and then one day, it didn't. I had made a change to the script recently, but i don't see how it would of changed anything considering it's an unrelated peice of code, and is also AFTER the ftp code.

    THe form for the script is correct, but for the sake of support, here it is.

    Code:
    <form name="post" method="post" action="add_query.php" enctype="multipart/form-data">
    
    <input type="hidden" name="MAX_FILE_SIZE" value="900000"> 
    <input name="FormFile" type="file" id="FormFile">
    <input type='submit'>
    </form>
     
  2. goldfish

    goldfish Lt. Sushi.DC

    Can you have it echo out some variables being put into the ftp_put() function? It might be a configuration changed which means the variables being passed are invalid or incorrect for some reason.

    Also, I'd probably remove the need for the $upload variable...
    PHP:
    if (!ftp_put($conn_id$_FILES['FormFile']['name'], $_FILES['FormFile']['tmp_name'], FTP_BINARY)) {
     
    // it failed
    }
     
  3. man_im_bored

    man_im_bored Private E-2

    Thanks Goldfish

    I'm pretty sure the problem isn't the code, but the server config, as you said yourself. It seems to be limited to files under 100k. (unless it's a php limitation).
    Thanks guys.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds