我有来自this link的图片。我想将它复制到我的服务器。这就是我尝试过的:
$url = 'http://tex.z-dn.net/?f=4%5E%7B13%7D%2A2%5E%7B-10%7D%3A16%5E%7B3%7D ';
function GetImageByURL($url, $path = null) {
$opts = array(CURLOPT_URL => $url,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10);
$ch = curl_init();
curl_setopt_array($ch, $opts);
$result = curl_exec($ch);
if ( (curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200
&& (strpos(curl_getinfo($ch, CURLINFO_CONTENT_TYPE), "image") !== false)))
{
$name = substr($url, strrpos($url, '/')+1);
if ($path) {
if (is_writeable($path))
file_put_contents(rtrim($path, '/') . '/' . $name, $result);
echo $result;
} else {
echo "error : {$path}";
}
return $name;
}
curl_close($ch);
return false;
}
但上述情况并不奏效。
这也不起作用:
$input = $url;
$output = 'imageimage.jpg';
file_put_contents($_SERVER['DOCUMENT_ROOT'].'/upload/1/',$output, file_get_contents($input));
答案 0 :(得分:-1)
777对文件夹的权限对我有用。