Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Thanked 1 Time in 1 Post

    can you use fput() to upload an external URL to your server?

    I have a form where users submit images. They can upload an image or they can point to an external URL for the image.

    If they point to an external URL for the image in my form I am trying to upload that image to my server. My host doesn't allow fopen() but does allow php ftp() functions like fput() (go figure??)

    Here is my code:

    $pixelURL='http://www.bluesnews.com/images/bluesLogo.gif'; // example external image
    $ftp_server = 'ftp.com';
    $ftp_user_name = 'myusername';
    $ftp_user_pass = 'mypassword';
    $conn_id = ftp_connect($ftp_server);
    $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    // check connection
    if ((!$conn_id) || (!$login_result)) { 
            echo "FTP connection has failed!";
            echo "Attempted to connect to $ftp_server for user $ftp_user_name"; 
        } else {
            echo "Connected to $ftp_server, for user $ftp_user_name";
    $target_path = "/home/mypath/www/img/subdir/";
    $destination_file = $target_path . 'fakefilename.gif';
    // upload the file
    $upload = ftp_put($conn_id, $destination_file, $pixelURL, FTP_BINARY); 
    echo '<p>'.print_r($upload).'</p>';
    // 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 
    interestingly I get the following output:

    Connected to ftp.com, for user username
    1 // output of print_r($upload)
    FTP upload has failed!
    I can connect but I can't upload. The subdir is chmod 777 by the way.

    I assume it is failing because the sourcefile is a URI... is this true?

    Last edited by Bobafart; 03-01-2008 at 05:30 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    In a place far, far away...
    Thanked 1,043 Times in 1,019 Posts
    Its likely they don't accept files from external sites. Just be advised that you are opening yourself up to a lot of security issues when doing this. Merely renaming the file may not be enough. Here is a good read http://www.eatmybusiness.com/food/20...-over-http/49/
    Last edited by _Aerospace_Eng_; 03-01-2008 at 05:32 PM.

  • Users who have thanked _Aerospace_Eng_ for this post:

    Bobafart (03-01-2008)

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Thanked 1 Time in 1 Post
    that was a very informative read

    i learned a lot

    i also learned that i wont do what i was planning to do due to the security risks

    uploading pictures is enough for me! thanks!


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts