Writing image to different domain

Discussion in 'PHP' started by ruby, Jan 25, 2008.

  1. #1
    Hi guys... I am working on something where I need to write an image from an HTML form input to a different domain.... here is the code:

    
    
    $a = rand(0,9999);
    $n = rand(0,9999);
    $d = rand(0,9999);
    $source = $_FILES[banner_file][tmp_name];
    $fileupload_name = $_FILES[banner_file][name];
    $fileupload_name = "$a$n$d-$fileupload_name";
    
    $uploadpath = "http://img.rubydomain.com/ads/";
    
    $dest = $uploadpath.$fileupload_name;
    
    if (copy($source,$dest)) { }
    
    
    Code (markup):
    When i run it though I get:

    
    Warning: copy(http://img.rubydomain.com/ads/img00001.gif) [function.copy]: failed to open stream: HTTP wrapper does not support writeable connections. in /var/www/rubydomain/test.php on line 10
    Code (markup):

    I have a form on www.rubydomain.com that I have a form which I select an image from my PC then submit the form. Normally I would save this file in the same domain but in this case I want to copy the file to a different domain (img.rubydomain.com), but its not letting me.

    Yes the http://img.rubydomain.com/ads/ directory is set to CHMOD 777.


    How can I do this? Is there another way?

    SURELY there is a way to write it to a different domain!!!
     
    ruby, Jan 25, 2008 IP
  2. HoagieKat

    HoagieKat Peon

    Messages:
    87
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try using PHP's built in FTP client.
     
    HoagieKat, Jan 25, 2008 IP
  3. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #3
    Any idea how? You got a code snippet?
     
    ruby, Jan 25, 2008 IP
  4. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Is the other domain on the same server, or a different server?

    You could always make a small script that accepts a POST request with the image data in one variable. And then send the image data from the original domain with CURL.
     
    tamen, Jan 25, 2008 IP
  5. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    sharqi, Jan 25, 2008 IP
  6. ruby

    ruby Well-Known Member

    Messages:
    1,854
    Likes Received:
    40
    Best Answers:
    1
    Trophy Points:
    125
    #6
    All sorted and working, I used FTP.
     
    ruby, Jan 25, 2008 IP
  7. HoagieKat

    HoagieKat Peon

    Messages:
    87
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Glad you got it sorted out
     
    HoagieKat, Jan 25, 2008 IP
  8. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #8
    even you can use curl

    Regards
    Alex
     
    kmap, Jan 25, 2008 IP