#1
  1. dont click here
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    409
    Rep Power
    13

    help putting files in an FTP through PHP.


    I need to figure out how to select a file on the users HD

    PHP Code:


    if u cant tell this code was talking from php.net
    <?php
    // set up basic connection
    $ftp_server="---";
    $ftp_user_name="---";
    $ftp_user_pass="---";
    $conn_id ftp_connect($ftp_server); 

    // login with username and password
    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass); 

    $source_file ="C:\Documents and Settings\Sho\Desktop\Advanced Web Design.ppt";

    $destination_file="awd.ppt";

    // check connection
    if ((!$conn_id) || (!$login_result)) { 
            echo 
    "FTP connection has failed!";
            echo 
    "Attempted to connect to $ftp_server for user $ftp_user_name"
            exit; 
        } else {
            echo 
    "Connected to $ftp_server, for user $ftp_user_name";
        }

    // upload the file
    $upload ftp_put($conn_id$destination_file$source_fileFTP_BINARY); 

    // check upload status
    if (!$upload) { 
            echo 
    "FTP upload has failed!";
        } else {
            echo 
    "Uploaded $source_file to $ftp_server as $destination_file";
        }

    // close the FTP stream 
    ftp_close($conn_id); 
    ?>
    i get an error showing it cant find the source file.. sicne PHP runs on the server i understand this error so how would i do this??
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    So you're saying $source_file isn't on the server? And you understand that that's the reason you get an error?

    You would need to use a form with an <input type="file" ...> to allow the file to be uploaded to the server via the form and then have your script FTP it to your destination.
  4. #3
  5. // no comment
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2001
    Posts
    1,645
    Rep Power
    39
    I need to figure out how to select a file on the users HD
    yep, jharnois is right, there's absolutely no way for any server side script to directly grab files from a users hard drive.
  6. #4
  7. dont click here
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    409
    Rep Power
    13
    Originally posted by jharnois
    So you're saying $source_file isn't on the server? And you understand that that's the reason you get an error?

    You would need to use a form with an <input type="file" ...> to allow the file to be uploaded to the server via the form and then have your script FTP it to your destination.
    so if i do that with the input it is automatically uploaded to the server once the form is submitted?
  8. #5
  9. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    Yes, <input type="file" will give a text-like input box with a browser button next to it. The user can browser their local machine and select a file to upload to the server. That file is uploaded to the server and then your script will have access to it, at which point you may FTP it. Read through the file upload section of the manual for information on how to handle file uploads.
  10. #6
  11. dont click here
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    409
    Rep Power
    13
    haha u learn something new everyday here.. never knew that..

IMN logo majestic logo threadwatch logo seochat tools logo