【发布时间】:2012-04-05 18:51:50
【问题描述】:
如何使用 php 从 URL 下载图像(例如:https://www.google.com/images/srpr/logo3w.png)然后保存? 这是我到目前为止想出的,它在'file_put_contents'函数中给了我一个错误。
<form method="post" action="">
<textarea name="text" cols="60" rows="10">
</textarea><br/>
<input type="submit" class="button" value="submit" />
</form>
<?php
$img = "no image";
if (isset($_POST['text']))
{
$content = file_get_contents($_POST['text']);
$img_path = '/images/';
file_put_contents($img_path, $content);
$img = "<img src=\"".$img_path."\"/>";
}
echo $img;
?>
它给了我错误:
[function.file-put-contents]: failed to open stream: No such file or directory in C:\wamp\www\img.php
/images/目录与php文件同目录,可写。
【问题讨论】:
-
1 分钟内回答 4 个!!希望您的问题很快得到解决。
-
您从未接受过任何答案?请投票并接受对您有帮助的答案。
-
@Rohit 很抱歉,我该如何接受答案?
-
@Rohit ok 知道如何接受 :)