PHP gets remote pictures to local
Release: 2016-07-25 08:42:51
Original
833 people have browsed it
- /*
- * Get remote image to local
- */
- function GrabImage($url){
- if($url != ""){ //If the image address is empty
- $ext = strrchr($url,'.'); //Determine the format of the image
- if($ext != '.jpg' && $ext != '.gif' && $ext != '$png'){
- return false;exit;
- }
- $filename_r = time().rand(10,9000).$ext; //Name the picture
- $filename = 'getimg/'.$filename_r;
- ob_start(); //Open the buffer Area
- readfile($url);
- $imginfo = ob_get_contents(); //Get the contents of the buffer
- ob_end_clean(); //Clear and close 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 program time'.$time.'seconds';
- ?>
Copy code
|
PHP
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31