Reputation: 9866
I'm just starting to learn cURL and now I simply try all kind of things to get used to the options that cURL give me.Here is a simple script which I use to connect and retrieve data from a current site
<?php
$ch=curl_init();
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt($ch, CURLOPT_URL, "http://img2.somesite.net/bitbucket/");
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a=curl_exec($ch);
curl_close($ch);
echo $a;
?>
I want to get the images stored there, but obviously I miss something.I'm not sure how it should be done.When you write http://img2.somesite.net/bitbucket/pic.jpg
the image is loaded.I want to get the name of all files that are there, or maybe I should trigger a command which will download the images and then check them on the PC...I don't know is this possible with cURL and hwo could be done?
Also when I leave it
http://somesite.net/
I get the resource back, so basicly this works...
Thanks
Leron
Upvotes: 0
Views: 629
Reputation: 13257
CURLOPT_HEADER is a boolean value determining whether it should return the requests' headers. To pass headers to cURL, you should use CURLOPT_HTTPHEADER.
This should work just fine:
<?php
$ch=curl_init();
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: "; // browsers keep this blank.
curl_setopt($ch, CURLOPT_URL, "http://img2.somesite.net/bitbucket/");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$a=curl_exec($ch);
curl_close($ch);
echo $a;
?>
Upvotes: 0
Reputation: 6052
Try setting a User-Agent, as Some sites block requests without a user agent.
Also, download Tamper Data for firefox and see the Headers being sent to the Server when you initiate the download from your browser. Imitiate all the Headers from curl and that will do it.
Thats how i do it.
Upvotes: 1