图像远程上载脚本

时间:2011-03-04 11:39:25

标签: php

我无法制作一个能够复制远程图像并将其保存到目录的php文件。

因此我将在第一个文本框中输入一组图像网址,运行时图像将抓取这些图像并将其保存到指定目录并显示新的网址集。 :)

我该怎么做?

3 个答案:

答案 0 :(得分:1)

将此代码放在script.php

<?php
$image = 'http://remote.com/image.jpeg';
file_put_contents(dirname(__FILE__).'/'.basename($image), file_get_contents('http://remote.com/image.jpeg'));

答案 1 :(得分:0)

我首先使用file_get_contents()以及fopen()fwrite()fclose()黑帮。

<?php
foreach( $_POST['image'] as $image ) {
    $f = fopen( "/path/to/image/folder/".basename( $image ) ); //Open image file
    fwrite( $f, file_get_contents( $image ) ); //Write the contents of the web image to the newly created image on your server
    fclose( $f ); //Close the file
}
?>

答案 2 :(得分:0)

这应该让你开始

header("Content-Type: image/jpeg");
echo file_get_contents("http://www.somewebsite.com/images/image.jpg");

然后,您可以将此文件保存到本地目录

相关问题