w1ww Established Member ★ 15 ★ Impact 9 Apr 16, 2007 3K views 7 replies #1 Hello, I'm wondering, using PHP how can I get an image from an url and save it to a folder? any example of coding? Thank you!
Hello, I'm wondering, using PHP how can I get an image from an url and save it to a folder? any example of coding? Thank you!
Eric VIP Member VIP ★ 20 ★ Impact 328 Apr 16, 2007 1 point #2 I'll use jp(e)g as an example. You can use a URL as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and Appendix N, List of Supported Protocols/Wrappers for a list of supported URL protocols. Click to expand... PHP: <?php $im = imagecreatefromjpeg($urltojpegimage); imagejpeg($im, 'path/to/file.jpg', 100); ?> http://us.php.net/imagecreatefromjpeg http://us.php.net/imagecreatefromgif http://us.php.net/imagecreatefrompng
I'll use jp(e)g as an example. You can use a URL as a filename with this function if the fopen wrappers have been enabled. See fopen() for more details on how to specify the filename and Appendix N, List of Supported Protocols/Wrappers for a list of supported URL protocols. Click to expand... PHP: <?php $im = imagecreatefromjpeg($urltojpegimage); imagejpeg($im, 'path/to/file.jpg', 100); ?> http://us.php.net/imagecreatefromjpeg http://us.php.net/imagecreatefromgif http://us.php.net/imagecreatefrompng
w1ww Established Member ★ 15 ★ Impact 9 Apr 16, 2007 #3 Thank you Eric, it seems easy ! I thought it was going to be hard to do it ! I'm going to test it right now! Thank you once again!
Thank you Eric, it seems easy ! I thought it was going to be hard to do it ! I'm going to test it right now! Thank you once again!
Dan Buy my domains.VIP Member VIP ★ 15 ★ Impact 108 Apr 16, 2007 #4 PHP: <?php $url = "http://url.to/file/here.png"; $data = file_get_contents($url); $name = explode("/", $url); $handle = fopen($name[count($name)-1], "w"); fwrite($handle, $data); fclose($handle); ?> Works for any type of file.
PHP: <?php $url = "http://url.to/file/here.png"; $data = file_get_contents($url); $name = explode("/", $url); $handle = fopen($name[count($name)-1], "w"); fwrite($handle, $data); fclose($handle); ?> Works for any type of file.
tm Established Member ★ 20 ★ Impact 25 Apr 17, 2007 #6 copy() is easier http://uk3.php.net/manual/en/function.copy.php
Dan Buy my domains.VIP Member VIP ★ 15 ★ Impact 108 Apr 17, 2007 #8 tm said: copy() is easier http://uk3.php.net/manual/en/function.copy.php Click to expand... Wow.. Nice.
tm said: copy() is easier http://uk3.php.net/manual/en/function.copy.php Click to expand... Wow.. Nice.