我在制作一个php文件时遇到了麻烦,它可以复制远程图像并将其保存到一个目录中。
因此,我将在第一个文本框中输入一组图像urls,当运行时,图像将捕获这些图像,并将它们保存到指定的目录中,并显示新的urls集。:)
我该怎么做呢?
发布于 2011-03-04 19:43:24
将此代码放入script.php中
<?php
$image = 'http://remote.com/image.jpeg';
file_put_contents(dirname(__FILE__).'/'.basename($image), file_get_contents('http://remote.com/image.jpeg'));发布于 2011-03-04 19:44:11
首先,我会使用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
}
?>发布于 2011-03-04 19:44:47
这应该会让你开始
header("Content-Type: image/jpeg");
echo file_get_contents("http://www.somewebsite.com/images/image.jpg");然后可以将此文件保存到本地目录
https://stackoverflow.com/questions/5193228
复制相似问题