Reputation: 2917
I need to copy an image from a server in order to create different types of images from it, like e.g. a thumbnail.
while it works ok with ImageCreateFromJPEG($picture_location);
it will also create a problem if the image is not available and take 30s to timeout.
Therefore I thought about downloading first with copy:
copy('http://www.server.com/file.jpg', '/tmp/file.jpeg');
Unfortunatelly there is also no way to decrease timeout if the connect fails or the image has been removed.
Is there a better way to achieve what I am intending? Thank you for any help on this.
Upvotes: 0
Views: 650
Reputation: 66
You can download file via curl which has timeout option.
<?php
$fp = fopen (dirname(__FILE__) . '/localfile.tmp', 'w+');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50); //timeout
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
Upvotes: 3