Home >Backend Development >PHP Tutorial >How Can I Copy Images Remotely Using PHP?
Copying Images Remotely via PHP with PHP5 and Earlier
It is possible to directly copy an image from a remote URL to your own server using PHP. Here are two ways to achieve this:
PHP5 Method:
<code class="php">copy('http://www.google.co.in/intl/en_com/images/srpr/logo1w.png', '/tmp/file.png');</code>
PHP4 and Earlier Method:
<code class="php">$content = file_get_contents("http://www.google.co.in/intl/en_com/images/srpr/logo1w.png"); $fp = fopen("/location/to/save/image.png", "w"); fwrite($fp, $content); fclose($fp);</code>
Configuration:
To successfully copy the image, ensure that the destination folder has 777 permissions. This will grant write access to the script.
The above is the detailed content of How Can I Copy Images Remotely Using PHP?. For more information, please follow other related articles on the PHP Chinese website!