Ec (2); * $ dirwww.111cn.net; & nbsp; if (strstr ($ src, & quot;) & amp ;! Strstr ($ src, $ _ SERVER [HTTP_HOST]) {& nbsp; $ srcgetimg ($ src); & nbsp ;}& nbsp; & nbsp; functiongetimg (script ec (2); script
*/
$ Dir = '/www.111cn.net ';
If (strstr ($ src, "http ://")&&! Strstr ($ src, $ _ SERVER ['HTTP _ host']) {
$ Src = getimg ($ src );
}
Function getimg ($ l1 ){
$ L2 = $ dir. '/'. substr (md5 ($ l1), 10, 10). strrchr ($ l1 ,".");
// The file exists and the address is returned directly.
If (file_exists ($ l2 )){
// Echo "exits ...";
Return $ l2;
}
// Get the file and return the new path
$ Img = file_get_contents ($ l1 );
If ($ img ){
If (! Is_dir ($ dir )){
@ Mkdir ($ dir );
}
Savefile ($ l2, $ img );
// Echo "file_get ..";
Return $ l2;
}
}
// Save the file (file, [content])
Function savefile ($ l1, $ l2 = ''){
If (function_exists (file_put_contents )){
File_put_contents ($ l1, $ l2 );
} Else {
$ Fp = @ fopen ($ l1, 'wb ');
@ Fwrite ($ fp, $ l2 );
Fclose ($ fp );
}
}
/*
The strrchr () function is used to locate the last occurrence of a string in another string and return all characters from this position to the end of the string.
The strstr () function searches for the first occurrence of a string in another string. This function returns the rest of the string (from the matching point ). If the searched string is not found, false is returned.
File_exists: determines whether a file exists. If yes, true or 1 is returned. If no, false or 0 is returned.
The file_get_contents () function reads the entire file into a string.
Mkdir: directory created. If the directory is successfully created, true or false
The file_put_contents () function writes a string to a file, just like calling the fopen (), fwrite (), and fclose () functions in turn.
This program is the homepage to determine whether the read address is network or local. If it is the image address of this server, it will not be processed. Otherwise, the remote server image or file will be downloaded to the local server.
*/
// This article was originally posted on www.111cn.net and indicated the source