Picture from other server

Discussion in 'PHP' started by Lukaslo, Dec 31, 2007.

  1. #1
    Lukaslo, Dec 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    
    $source = 'http://www.google.com/intl/en_ALL/images/logo.gif';
    $target = 'folder/logo.gif';
    
    copy($source, $target);
    
    PHP:
    Very basic example.
     
    nico_swd, Dec 31, 2007 IP
  3. Lukaslo

    Lukaslo Peon

    Messages:
    751
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey what is the alternative, because I'm getting:
    copy() [function.copy]: URL file-access is disabled in the server configuration
     
    Lukaslo, Dec 31, 2007 IP
  4. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You could try this basic example, although i'm sure nico has some slick solution there too :)
    
    <?php
    
    $image_url = "http://www.google.com/intl/en_ALL/images/logo.gif";
    
    // Grab the image data
    $image_data = file_get_contents($image_url);
    
    // Extract the original image name
    $image_name = basename($image_url);
    
    // Save the image
    $fp = fopen($image_name, "w");
    fwrite($fp, $image_data);
    fclose($fp);
    
    ?>
    
    PHP:
    p.s. just noticed, that the problem is probably not in the copy function, but could be in using all other url open based solutions. In that case you could try using cURL.
     
    hogan_h, Dec 31, 2007 IP
  5. Lukaslo

    Lukaslo Peon

    Messages:
    751
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok thank you. I just found a solution liste in dreamhost wiki:

    $ch = curl_init($source);
    $fp1 = fopen($target, "w");
    curl_setopt($ch, CURLOPT_FILE, $fp1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp1);

    Thank you ;) If you got any other alternatives I'll be glad to hear
     
    Lukaslo, Dec 31, 2007 IP