Home >Backend Development >PHP Tutorial >How Can I Copy Images Remotely Using PHP?

How Can I Copy Images Remotely Using PHP?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-18 22:52:03420browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn