PHP downloads remote files and get file content

/ ** * Get the content of the remote file * @parma $ url url * @return get content * ** / public static function getContent ($ URL) {$ FLAG = 0; do {$ hCurl = curl_init (); curl_setopt ($ hCurl, CURLOPT_HEADER, 0); curl_setopt ($ hCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ hCurl, CURLOPT_TIMEOUT, 120); curl_setopt ($ hCurl, CURLOPT_CONNECTTIMEOUT, 4); curl_setopt ($ hCurl , CURLOPT_URL, $ url); $ data = curl_exec ($ hCurl); if (curl_errno ($ hCurl)) {break;} $ http_code = curl_getinfo ($ hCurl, CURLINFO_HTTP_CODE); if ($ http_code> = 400) {// 400 – 600 is Server ErrorBreak;} $ FLAG = 1;} while (0); curl_close ($ hcurl); if ($ flag) {Return $ data;}}} / ** * Download Remote File Save local file * @Parma $ filename Save File * @PARMA $ URL URL * @return Getting content * ** / public static function getContentToftTOFile ($ filename, $ url) {$ out = fopen ($ filename, ‘w’); if (Empty ($ out) {Return False; } $ flag = 0; do {$ hCurl = curl_init (); curl_setopt ($ hCurl, CURLOPT_HEADER, 0); curl_setopt ($ hCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ hCurl, CURLOPT_TIMEOUT, 120); curl_setopt ($ hCurl, CURLOPT_CONNECTTIMEOUT, 4); curl_setopt ($ hCurl, CURLOPT_FILE, $ out); curl_setopt ($ hCurl, CURLOPT_URL, $ url); $ data = curl_exec ($ hCurl); if (curl_errno ($ hCurl)) {break;} $ http_code = Curl_getinfo ($ hcurl, curlinfo_http_code); if ($ http_code> = 400) {// 400 – 600 is Server ErrorBreak;} $ flag = 1;} while (0); curl_close ($ hcurl); fclose ($ out) ; if ($ flag) {Return $ data;} else {return false;}}
   
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment