Hi,
I am new to PHP and I have written this code which downloads image from URL
foreach ($content->find('img[id=prodImage]') as $element){
// echo("FOUND "$element);
$ch = curl_init($element->src);
$filename = parse_url($_POST[$url], PHP_URL_HOST).'_'.time();
echo($filename);
$ext = substr($element->src, -3);
echo($ext);
if(!is_dir('parsed_items'))
mkdir("parsed_items", 0777);
$fp = fopen('parsed_items/'.$filename.'.'.$ext, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
But whenever I reach curl_exec($ch) the entire contents are dumped on the screen. It works fine at other places. Please guide me as to how can I resolve this or any other API which will let me download the image
Tks & Rgds,
Manoj
Facing problem with Image downloader code from URL
Moderator: General Moderators
Re: Facing problem with Image downloader code from URL
You'll need to pull apart from result which is given by curl_exec. It will essentially just pull all of the HTML code from the page, so you have to sort through it to get the data you need.