<?php $url = 'http://img0.bdstatic.com/img/image/239d4628535e5dde711b5271485a5efce1b9c1661cf.jpg'; $result = getimgsize($size); var_dump($result);
抓取遠程圖片, php
//驗證Url是否合法,防止file_get_contens($url)報warning錯誤。 if (check_url($url)) { $bin = file_get_contents($url);//獲取到圖片的二進制數據 $fp = fopen('xxx.jpg', 'w'); fwrite($fp, $bin);//數據保存到xxx.jpg中。 fclose($fp); } function check_url($url) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_NOBODY, true); $result = curl_exec($curl); $found = false; // 若是請求沒有發送失敗 if ($result !== false) { // 再檢查http響應碼是否爲200 $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 200) { $found = true; } } curl_close($curl); return $found; }