This article provides a paragraph about saving the image to this address through the image address from an ajax instance of mine. Here we read it directly through readfile and then save it through fopen
Example
The code is as follows
代码如下 |
复制代码 |
/**
* 通过图片的远程url,下载到本地
* @param: $url为图片远程链接
* @param: $filename为下载图片后保存的文件名
*/
function GrabImage($url,$filename) {
if($url==""):return false;endif;
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
//"../../images/books/"为存储目录,$filename为文件名
$fp2=@fopen("../../images/books/".$filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
?>
|
|
Copy code
|
|
/**
* Download to local through the remote url of the image
* @param: $url is the remote link to the image
* @param: $filename is the file name saved after downloading the image
*/
function GrabImage($url,$filename) {
if($url==""):return false;endif;
ob_start();
readfile($url);
$img = ob_get_contents();
ob_end_clean();
$size = strlen($img);
//"../../images/books/" is the storage directory, $filename is the file name
$fp2=@fopen("../../images/books/".$filename, "a");
fwrite($fp2,$img);
fclose($fp2);
return $filename;
}
?>
The function returns the name saved after downloading the image, then you only need to store the image directory + image name in the database.
http://www.bkjia.com/PHPjc/631524.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/631524.htmlThis article provides a paragraph from an ajax instance of mine about saving pictures to this address through the picture address, here We can read it directly through readfile and save it through fopen. The example code is as follows...