note 110162 added to function.curl-setopt

From: Date: Tue, 25 Sep 2012 08:47:36 +0000
Subject: note 110162 added to function.curl-setopt
Groups: php.notes 
Request: Send a blank email to php-notes+get-191012@lists.php.net to get a copy of this message
I've created an example that gets the file on url passed to script and outputs it to the browser. <?php //get the file (e.g. image) and output it to the browser $ch = curl_init(); //open curl handle curl_setopt($ch, CURLOPT_URL, $_GET['url']); //set an url curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //do not output directly, use variable curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); //do a binary transfer curl_setopt($ch, CURLOPT_FAILONERROR, 1); //stop if an error occurred $file=curl_exec($ch); //store the content in variable if(!curl_errno($ch)) { //send out headers and output header ("Content-type: ".curl_getinfo($ch, CURLINFO_CONTENT_TYPE).""); header ("Content-Length: ".curl_getinfo($ch, CURLINFO_CONTENT_LENGTH_DOWNLOAD).""); echo $file; } else echo 'Curl error: ' . curl_error($ch); curl_close($ch); //close curl handle ?> p.s. Make sure that there're no new lines before and after code or script may not work. ---- Server IP: 69.147.83.199 Probable Submitter: 78.62.166.166 ---- Manual Page -- http://www.php.net/manual/en/function.curl-setopt.php Edit -- https://master.php.net/note/edit/110162 Del: integrated -- https://master.php.net/note/delete/110162/integrated Del: useless -- https://master.php.net/note/delete/110162/useless Del: bad code -- https://master.php.net/note/delete/110162/bad+code Del: spam -- https://master.php.net/note/delete/110162/spam Del: non-english -- https://master.php.net/note/delete/110162/non-english Del: in docs -- https://master.php.net/note/delete/110162/in+docs Del: other reasons-- https://master.php.net/note/delete/110162 Reject -- https://master.php.net/note/reject/110162 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#191012) next »