//
Function: Get the remote picture and save it locally
//
//
Make sure you have permission to write files to the local server
//
//
Variable Description:
$url is the full URL address of the remote picture and cannot be empty.
$filename is an optional variable: If blank, the local file name will be based on the time and date
Automatically generated.
function Grabimage ($url, $filename = "") {
if ($url = = ""): return false;endif;
if ($filename = = "") {
$ext =STRRCHR ($url, ".");
if ($ext! = ". gif" && $ext! = ". jpg"): return false;endif;
$filename =date ("Dmyhis"). $ext;
}
Ob_start ();
ReadFile ($url);
$img = Ob_get_contents ();
Ob_end_clean ();
$size = strlen ($img);
$FP 2= @fopen ($filename, "a");
Fwrite ($fp 2, $img);
Fclose ($fp 2);
return $filename;
}
$img =grabimage ("/upload/20081208002838680.jpg", "" ");
if ($img): Echo '
'; Else:echo "false"; endif;
>dedecms: if (!empty ($saveremoteimg))
{
$body = Stripslashes ($body);
$img _array = Array ();
Preg_match_all ("/(src| SRC) =[\ "|" | {0,} (http:\/\/(. *) \. (gif|jpg|jpeg|bmp|png)) /isu ", $body, $img _array);
$img _array = Array_unique ($img _array[2]);
Set_time_limit (0);
$IMGURL = $img _dir. " /". Strftime ("%y%m%d ", Time ());
$imgPath = $base _dir. $imgUrl;
$milliSecond = strftime ("%h%m%s", Time ());
if (!is_dir ($imgPath)) @mkdir ($imgPath, 0777);
foreach ($img _array as $key = $value)
{
$value = Trim ($value);
$get _file = @file_get_contents ($value);
$rndFileName = $imgPath. " /". $milliSecond. $key.". ". substr ($value, -3,3);
$fileurl = $imgUrl. " /". $milliSecond. $key.". ". substr ($value, -3,3);
if ($get _file)
{
$fp = @fopen ($rndFileName, "w");
@fwrite ($fp, $get _file);
@fclose ($FP);
}
$body = Ereg_replace ($value, $fileurl, $body);
}
$body = Addslashes ($body);
}
The above describes the Save Web page as a picture PHP remote image saved to the local function class, including saving the page as a picture of the content, I hope that the PHP tutorial interested in a friend helpful.