[nycphp-talk] images with cURL
harvey
list at harveyk.com
Wed Mar 15 21:45:17 EST 2006
I clicked your link and the page looks fine to me.
Some red radio thingy image displayed.
Firefox 1.5, WinXP.
At 08:14 PM 3/15/2006, Joseph Crawford wrote:
>Hello guys,
>
>i am having an issue here, i am trying to display images on a site
>with it masking the actual image location, we are grabbing circuit
>city's images (with permission)
>to be shown on our site, we have all the url's in the db so i
>created an image.php file that we will use in our image links, here it is
>
><?php
>include_once('config/config.php');
>include_once(LIBRARY.'ConnectionPool.php');
>
>$imgType = (isset($_GET['type'])) ? ucfirst($_GET['type']) : 'Item';
>$rowID = (isset($_GET['img'])) ? $_GET['img'] : null;
>
>if(!is_null($rowID)) {
> $dblink = new ConnectionPool(true);
> $sql = "SELECT ".$imgType."_Image as image FROM MasterItems
> WHERE Record_ID=".$rowID;
> $res = $dblink->db_query($sql);
> $row = $dblink->db_fetch_object($res);
>
> $cookieFile = BASE_PATH.'cache/circuitcities.cookie.txt';
>
> $ch = curl_init($row->image);
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> curl_setopt($ch, CURLOPT_REFERER,
> '<http://circuitcity.com/'>http://circuitcity.com/');
> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U;
> Windows NT 5.1; en-US; rv:<http://1.8.0.1>1.8.0.1) Gecko/20060111
> Firefox/1.5.0.1");
> curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate");
> curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
> curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
> curl_setopt($ch, CURLOPT_HTTPHEADER, array(
> "Accept:
> text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=
> 0.5",
> ));
> $source = curl_exec($ch);
> curl_close($ch);
> header("content-type: image/jpeg");
> echo $source;
>}
>?>
>
>In FireFox when you hit the page you see a broken image (txt url in
>mine) however if you view source you see the binary from the image.
>
>This works fine if i hard code the url in curl_init, and i have
>tried urlencode() and trim() on the url before feeding it to curl.
>
>you can see the file in use here
>
><http://b2cdev.licketyship.com/image.php?img=50903>http://b2cdev.licketyship.com/image.php?img=50903
>
>Any help would be appreciated.
>
>Thanks,
>
>--
>Joseph Crawford Jr.
>Zend Certified Engineer
>Codebowl Solutions, Inc.
><http://www.codebowl.com/>http://www.codebowl.com/
>1-802-671-2021
><mailto:codebowl at gmail.com>codebowl at gmail.com
>_______________________________________________
>New York PHP Community Talk Mailing List
>http://lists.nyphp.org/mailman/listinfo/talk
>New York PHP Conference and Expo 2006
>http://www.nyphpcon.com
>Show Your Participation in New York PHP
>http://www.nyphp.org/show_participation.php
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060315/18ce147d/attachment.html>
More information about the talk
mailing list