& Nbsp; & lt ;? PhpclassCollection {protected $ url; collection address protected $ prefix; rename the file prefix protected $ style; format of the image to be collected, input an array constprel (? : Http? | Https ?) :(? : [^. ()?] +) Class Collection {
Protected $ url; // Collection Address
Protected $ prefix; // rename the file prefix
Protected $ style; // The format of the image to be collected. input an array.
Const prel = '/(? : Http? | Https ?) :\/\/(? : [^ \. \/\ (\) \?] + )\.(? : [^ \. \/] + )\.(? : Com | cn | net | org )\/(? : [^ \.: \ "\ '\ (\) \?] +) \. (Jpg | png | gif)/I '; // collection rules
// Constructor
Function _ construct ($ url, $ prefix, $ style ){
Switch ($ this-> checkdata ($ url, $ prefix, $ style )){
Case 1:
Echo 'script alert ("collection address cannot be blank! ") Script ';
Exit;
Break;
Case 2:
Echo 'script alert ("The format of the image to be collected, which should be an array! ") Script ';
Exit;
Break;
Case 3:
Echo 'script alert ("The format of the image to be collected. it cannot be blank! ") Script ';
Exit;
Break;
Case 4:
Echo 'script alert ("the file name cannot contain./| or start with a space! ") Script ';
Exit;
}
$ This-> url = $ url;
$ This-> prefix = $ prefix;
$ This-> style = $ style;
}
// Start data collection
Public function action (){
$ Url = $ this-> checkurl ();
$ Imgurl = $ this-> collecturl ($ url );
$ This-> savafile ($ imgurl );
}
// Url processing
Protected function checkurl (){
$ Munprel = '/\ ([0-9] +, [0-9] + \)/I ';
$ Myurl;
If (preg_match ($ munprel, $ this-> url, $ arr )){
$ Temp = substr ($ arr [0], 1, strlen ($ arr [0])-2 );
$ Mymunber = explode (',', $ temp );
$ Temparr = explode ($ arr [0], $ this-> url );
For ($ I = $ mymunber [0]; $ I <= $ mymunber [1]; $ I ++ ){
$ Myurl [] = $ temparr [0]. $ I. $ temparr [1];
}
} Else {
$ Myurl = $ this-> url;
}
Return $ myurl;
}
// Save the file
Protected function savafile ($ imgurl ){
If (! Empty ($ imgurl )){
Foreach ($ imgurl [0] as $ key => $ value ){
$ Filename = '';
If (in_array ($ imgurl [1] [$ key], $ this-> style )){
$ Size = @ getimagesize ($ value );
If ($ size = false ){
Continue;
}
List ($ w, $ h, $ t, $ a) = $ size;
If ($ w <200 | $ h <200 ){
Continue;
}
Ob_start ();
Readfile ($ value );
$ Obj = ob_get_contents ();
Ob_end_clean ();
$ Dir = 'F:/php /';
If (! Is_dir ($ dir )){
Mkdir ($ dir, 0777 );
}
If (! Empty ($ this-> prefix )){
$ Filename = $ dir. $ this-> prefix. date ('ymmd'). rand (Random, 99999). '.'. $ imgurl [1] [$ key];
} Else {
$ Filename = $ dir. date ('ymd'). rand (Random, 99999). '.'. $ imgurl [1] [$ key];
}
$ Fo = @ fopen ($ filename, 'WB ');
If ($ fo === false ){
Echo 'script alert ("file creation failed, file directory cannot be written! ") Script ';
Exit;
}
$ Fw = fwrite ($ fo, $ obj );
Echo'
'. $ Filename.' collection successful
';
}
}
}
}
// Address Collection function, including image suffix
Protected function collecturl ($ url ){
Set_time_limit (0 );
If (is_array ($ url )){
$ Arr = array ();
$ Imgkey = array ();
Foreach ($ url as $ value ){
$ Code = file_get_contents ($ value );
12 Next page