[SOLVED] proxy server, CURL & images
Posted: Wed Apr 07, 2004 4:18 pm
hi,
this problem is driving me insane!
i am behind proxie server and wish to download images from the internet so i can store them into a mysql database...im using Curl and have it setup fine, the function below is about to initialise the get LoadImage function:
after the type is verified the loadimage function is called with the valid url being passed to it:
can ANYONE please help me? whats going wrong above?? i placed an echo just before the "return $data" and that echo comes up. but no image is saved?
just incase, the save function is below...
this problem is driving me insane!
i am behind proxie server and wish to download images from the internet so i can store them into a mysql database...im using Curl and have it setup fine, the function below is about to initialise the get LoadImage function:
Code: Select all
<?php
function storeImageURL($url,$id,$table = "item") {
$type = getImageType($url);
if ($type === FALSE) return FALSE;
$data = loadImage($url);
if ($data === FALSE) return FALSE;
$rtn = saveImage($id,$data,$type,$table);
}
?>Code: Select all
<?php
function loadImage($url)
{
//useful function
//@param resource $cx connection
//@param array $opts array of options: array(option_name => option_value)
//@return void
$cx = curl_init($url); // create the connection
curl_set_options($cx, array('returntransfer' => true, 'followlocation' => true)); // set connection options
$data = curl_exec($cx); // execute the request
curl_close($cx);
return $data;
// now $result holding the response of the remote server: image, html error-page, nothing - whatever.
// check the PHP manual, cURL chapter for more options, such as proxies, authentication etc.
}
?>just incase, the save function is below...
Code: Select all
<?php
function saveImage($id,$data,$type,$table = "item") {
//clean up the data so SQL can understand it.
$data = str_replace("","\",$data);
$data = str_replace("'","\''",$data);
$result = query("UPDATE $table set imagetype = '$type', image = '$data' where item_id = '$id'");
}
?>