I have this script which cut my image in half fine, but when I change the filename to be http://www.mysecondsite.com/418.jpg I get the error below

How can I fix this?

<?php
// File and new size
$filename = '418.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?> 

<br />
<b>Warning</b>: getimagesize(http://www.myfirstsite.com/travel/album/mid/418.jpg): failed to open stream: No route to host in <b>/home3/kiwis/public_html/thumb.php</b> on line <b>10</b><br />
<br />
<b>Warning</b>: imagecreatetruecolor(): Invalid image dimensions in <b>/home3/kiwis/public_html/thumb.php</b> on line <b>15</b><br />
<br />
<b>Warning</b>: imagecreatefromjpeg(http://www.myfirstsite.com/travel/album/mid/418.jpg): failed to open stream: No route to host in <b>/home3/kiwis/public_html/thumb.php</b> on line <b>16</b><br />
<br />
<b>Warning</b>: imagecopyresized(): supplied argument is not a valid Image resource in <b>/home3/kiwis/public_html/thumb.php</b> on line <b>19</b><br />
<br />
<b>Warning</b>: imagejpeg(): supplied argument is not a valid Image resource in <b>/home3/kiwis/public_html/thumb.php</b> on line <b>22</b><br />

    PHP is unable to access the image information on the remote host (at least if I understand the "myfirstsite.com" and "mysecondsite.com").

    If I remember correctly, the last time I wrote a script dealing with images on a remote host, I had to use the copy() function to store the image on the localhost, then transform the image. You might try that and see if it works.

      "No route to host"

      Either you mistyped the sitename and path (copy and paste the exact URL into your browser - does it work?). If it does work, try using [man]copy/man as suggested above to copy the remote file onto your server's drive and then use the local filename in the script.

      If the site loads fine for you, but a copy() fails, I suspect one of two things:

      1. The server is firewalled or set up to disallow scripts from accessing remote locations.
      2. There is a DNS error with the server, preventing it from making outgoing requests properly.
        Write a Reply...