Ftp upload question

Discussion in 'PHP' started by lammspillning, Mar 30, 2009.

  1. #1
    When this is on my server, how would I write the path ($source_file) to a file on my local computer?
    And how can I put the file inside my created folder?

    <?php
    // set up basic connection
    $conn_id = ftp_connect("ftp.mysite.com"); 
    
    // login with username and password
    $login_result = ftp_login($conn_id, "user", "pass"); 
    
    // check connection
    if ((!$conn_id) || (!$login_result)) { 
            echo "Failed!";
            exit; 
        } else {
            echo "Connected";
        }
    
    $source_file = 'path to my file on local computer';
    $destination_file = 'destinationName.avi';
    
    // Destination directory
    $dir = $_SERVER['DOCUMENT_ROOT'].'/uploadedFiles/'; 
    
    // Make directory
    $newFolder = mkdir($dir.'myFolder',0777);
    
    // upload the file
    $upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY); 
    
    // check upload status
    if (!$upload) { 
            echo "FTP upload has failed!";
        } else {
            echo "Uploaded";
        }
    
    // close the FTP stream 
    ftp_close($conn_id); 
    ?>
    PHP:

     
    lammspillning, Mar 30, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    Uhm. You can't, if I understand you correctly. PHP can't automatically access files on your local computer (thank heavens).

    You can, however, make a form where you have a file browser/input and you select the file - the rest of the task can be automated as you want it to be.

    Google for "upload files with php ftp" or something similar.
     
    PoPSiCLe, Mar 30, 2009 IP
  3. lammspillning

    lammspillning Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok, I was just wondering how the path will look like when it's sent to the PHP script. will it be "C:\user\myfile.jpg" or what will the path be?
     
    lammspillning, Mar 30, 2009 IP
  4. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    It is completely irrelevant? It's not sent anything to the PHP-script - you chose a location on your local computer, and the file saves itself there - it's not being sent any information as to where you save it to the PHP-file.
     
    PoPSiCLe, Mar 31, 2009 IP