NameSilo

[PHP] Get image from url

SpaceshipSpaceship
Watch

w1ww

Established Member
Impact
9
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!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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.

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
 
1
•••
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!
 
0
•••
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. ;)
 
0
•••
I'll try both, thank you Dan :)
 
0
•••
0
•••
Thank you, tm. I will try yours too!
 
0
•••
0
•••
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back