Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    417
    Thanks
    168
    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:

    Code:
    <?php
    $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"; 
            exit; 
        } 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 
    ftp_close($conn_id);
    ?>
    interestingly I get the following output:

    Code:
    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?

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

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    Bobafart (03-01-2008)

  • #3
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    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
    •