PHP remote image retrieval to local
- /*
- * Remote image retrieval to local
- */
- Function GrabImage ($ url ){
- If ($ url! = "") {// If the image address is blank
- $ Ext = strrchr ($ url, '.'); // you can specify the image format.
- If ($ ext! = '.Jpg '& $ ext! = '.Gif '& $ ext! = '$ Png '){
- Return false; exit;
- }
- $ Filename_r = time (). rand (). $ ext; // name the image
- $ Filename = 'getimg/'. $ filename_r;
- Ob_start (); // open the buffer
- Readfile ($ url );
- $ Imginfo = ob_get_contents (); // Obtain the buffer content
- Ob_end_clean (); // clears and closes the buffer.
- $ Fp = fopen ($ filename, 'A ');
- Fwrite ($ fp, $ imginfo );
- Fclose ($ fp );
- } Else {
- Return false;
- }
- }
- $ Start_time = microtime (true );
- GrabImage ("http://img4.shougongke.com/Public/advance/53846840dafb4.jpg ");
- $ End_time = microtime (true );
- $ Time = round ($ end_time-$ start_time, 3 );
- Echo 'total application time '. $ time. 'second ';
- ?>
|
PHP