upload to ftp through a php script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • printline
    New Member
    • Jul 2006
    • 89

    upload to ftp through a php script

    Hi' all

    I have a strange problem when uploading files from a form to my ftp site.

    Here is my code:

    [PHP]<?php
    $myFile = $_FILES['file']; // This will make an array out of the file information that was stored.
    $file = $myFile['tmp_name']; //Converts the array into a new string containing the path name on the server where your file is.
    $myFileName = $_POST['MyFile']; //Retrieve file path and file name
    $myfile_replace = str_replace('\\ ', '/', $myFileName); //convert path for use with unix
    $myfile = basename($myfil e_replace); //extract file name from path
    $destination_fi le = "/webshop/".$myfile; //where you want to throw the file on the webserver (relative to your login dir)
    // connection settings
    $ftp_server = "ftp.printline. dk"; //address of ftp server (leave out ftp://)
    $ftp_user_name = "xxxxxxxx"; // Username
    $ftp_user_pass = "xxxxxxxx"; // Password
    $conn_id = ftp_connect($ft p_server); // set up basic connection
    // login with username and password, or give invalid user message
    $login_result = ftp_login($conn _id, $ftp_user_name, $ftp_user_pass) or die("<h1>You do not have access to this ftp server!</h1>");
    $upload = ftp_put($conn_i d, $destination_fi le, $file, FTP_BINARY); // upload the file
    if (!$upload) { // check upload status
    echo "<h2>FTP upload of $myFileName has failed!</h2> <br />";
    }
    /*
    // try to delete $file
    if (ftp_delete($co nn_id, $destination_fi le)) {
    echo "$destination_f ile has been deleted!\n";
    } else {
    echo "Could not delete $destination_fi le!\n";
    }
    */
    ftp_close($conn _id); // close the FTP stream
    ?>[/PHP]

    And this works okay, but when i upload files that has a size between about 1 MB - 2MB i get this error:

    Warning: ftp_put(): Connection closed; transfer aborted. in D:\Webs\printli ne-webshop.eu\http docs\konto\plac eorder.php on line 15

    FTP upload of Y:\\Medie-Design\\printli neweb\\www\\dow nloads\\alphast ar_Process_summ ary.zip has failed!

    But the file goes into my folder on my ftp site.

    When i then upload files biger than 2 MB i get this error:

    FTP upload of Y:\\Medie-Design\\printli neweb\\www\\dow nloads\\artikel 1.zip has failed!

    And the files doesn't go into my ftp site.

    My webprovider has an upload limit size of 2MB in their php ini file but i can't see this as a problem when i upload to my ftp site, which is located on a local windows 2003 server. OR is this a problem..????

    Does anyone know why this happens, and maybe give me a solution to work around this...?

    Thanks in advance!
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    Hi,

    I've recently had some issue with the FTP stuff in PHP. It seemed to me that the ini file set a maximum post size as well as a file upload size. As far as I can tell, and I'm no expert (anyone correct me?) you can't load files that exceed either size.

    That's about all I know, fortunately for me my host has 8MB size so that's not too bad but still a pain.

    If anyone has a better answer please post as I'd love to know how to get around this.

    Nathj

    Comment

    • developing
      New Member
      • Mar 2007
      • 110

      #3
      post_max_size in php.ini needs to meet your requirement. maybe even upload_max_file size, not too sure about that though.

      you can read/change these values at runtime using ini_get() and ini_set()

      also, ini_get() and ini_set() don't work with all settings. youll have to find out if they will work with post_max_size.. .i cant remember

      Comment

      Working...