Copy Image from Remote Server Over HTTP Copy Image from Remote Server Over HTTP php php

Copy Image from Remote Server Over HTTP


If you have PHP5 and the HTTP stream wrapper enabled on your server, it's incredibly simple to copy it to a local file:

copy('http://somedomain.com/file.jpeg', '/tmp/file.jpeg');

This will take care of any pipelining etc. that's needed. If you need to provide some HTTP parameters there is a third 'stream context' parameter you can provide.


use

$imageString = file_get_contents("http://example.com/image.jpg");$save = file_put_contents('Image/saveto/image.jpg',$imageString);


PHP has a built-in function file_get_contents(), which reads the content of a file into a string.

<?php//Get the file$content = file_get_contents("http://example.com/image.jpg");//Store in the filesystem.$fp = fopen("/location/to/save/image.jpg", "w");fwrite($fp, $content);fclose($fp);?>
If you wish to store the file in a database, simply use the $content variable and don't save the file to disk.