note 83541 added to curl.examples

From: Date: Fri, 30 May 2008 20:47:31 +0000
Subject: note 83541 added to curl.examples
Groups: php.notes 
Request: Send a blank email to php-notes+get-140016@lists.php.net to get a copy of this message
Basic cURL file or page download with basic error trapping. <?php function cURLcheckBasicFunctions() { if( !function_exists("curl_init") && !function_exists("curl_setopt") && !function_exists("curl_exec") && !function_exists("curl_close") ) return false; else return true; } /* * Returns string status information. * Can be changed to int or bool return types. */ function cURLdownload($url, $file) { if( !cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions"; $ch = curl_init(); if($ch) { $fp = fopen($file, "w"); if($fp) { if( !curl_setopt($ch, CURLOPT_URL, $url) ) return "FAIL: curl_setopt(CURLOPT_URL)"; if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)"; if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)"; if( !curl_exec($ch) ) return "FAIL: curl_exec()"; curl_close($ch); fclose($fp); return "SUCCESS: $file [$url]"; } else return "FAIL: fopen()"; } else return "FAIL: curl_init()"; } // Download from 'example.com' to 'example.txt' echo cURLdownload("http://www.example.com", "example.txt"); ?> - JLèé ---- Server IP: 69.147.83.197 Probable Submitter: 122.53.223.92 ---- Manual Page -- http://www.php.net/manual/en/curl.examples.php Edit -- https://master.php.net/note/edit/83541 Del: integrated -- https://master.php.net/note/delete/83541/integrated Del: useless -- https://master.php.net/note/delete/83541/useless Del: bad code -- https://master.php.net/note/delete/83541/bad+code Del: spam -- https://master.php.net/note/delete/83541/spam Del: non-english -- https://master.php.net/note/delete/83541/non-english Del: in docs -- https://master.php.net/note/delete/83541/in+docs Del: other reasons-- https://master.php.net/note/delete/83541 Reject -- https://master.php.net/note/reject/83541 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140016) next »