function Get_file ($url, $folder) {
Set_time_limit (* *);
$destination _folder = $folder? $folder. ' /': '///File Download save directory
$newfname = $destination _fol Der. BaseName ($url);
$file = fopen ($url, "RB");
if ($file) { &nbs P
$NEWF = fopen ($newfname, "WB");
if ($NEWF)
while (!feof ($file)) {&N bsp;
Fwrite ($NEWF, Fread ($file, 1024 * 8), 1024 * 8);
}
}
if ($file) {
fclose ($file);
} ;
if ($NEWF) {
fclose ($NEWF);
}
}& nbsp;
PHP Tutorial Method Two
$url is the full URL address of the remote picture and cannot be empty.
$filename is an optional variable: If NULL, local file names are based on 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 ("Yun_qi_img/000003.png", "www.111cn.net.png");
if ($img): Echo ' <pre></pre> ';
Else:echo "false";
endif
fopen Download remote file function: Incoming remote URL and folder name where download files need to be stored, end without backslash
ASP tutorial Save remote server picture
/*
Sub Saveremotefile (Localfilename,remotefileurl)
Dim ads,retrieval,getremotedata
Set retrieval = Server.CreateObject ("Microsoft.XMLHTTP")
With retrieval
. Open "Get", Remotefileurl, False, "", ""
. Send
Getremotedata =. Responsebody
End With
Set retrieval = Nothing
Set ads = Server.CreateObject ("ADODB.stream")
With ads
. Type = 1
. Open
. Write Getremotedata
. SaveToFile localfilename,2
. Cancel ()
. Close ()
End With
Set ads=nothing
End Sub
Remotefileurl = "' Get remote picture
Fileext = Right (remotefileurl,4) ' Gets the format of the remote picture
' Random file name
Randomize
rannum = Int (9*10^3*rnd) +10^3
Dtnow = Now ()
filename = year (Dtnow) & Right ("0" & Month (Dtnow), 2) & Right ("0" & Day (Dtnow), 2) & Right ("0" & Hou R (Dtnow), 2 & Right ("0" & Minute (Dtnow), 2) & Right ("0" & Second (Dtnow), 2) & Rannum & Fileext
LocalFilename = "./" ' Save Local Path
If Right (localfilename,1) <> "/" Then LocalFilename = LocalFilename & "/"
SaveFile = Server.MapPath (localfilename & filename)
Saveremotefile savefile,remotefileurl ' Save remote picture
Response.Write "Save success, <a href=" "" "& LocalFilename & filename &" "target=" "_blank" "> Click to view Picture file ... </ A> "
*/
Method Three
/* Save Picture function/*
function SaveImage ($url)//Save the picture file in the URL to the local imges folder, the name does not change, return the path and name of the picture
{
if ($url = = ""): return false;endif;
/* Save Path/*
$path = "movieimg/". Date (' y-m-d '); Save path
if (!file_exists ($path))
{
Check if there is a folder, if it is not created, and gives the highest permissions
mkdir ("$path", 0700);
}
$name =STRRCHR ($url, "/");
$filename = $path. $name;
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;
}
?>