How to read/to download attachment on an URI? [message #172491] |
Mon, 21 February 2011 10:59  |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
$contents = stream_get_meta_data($handle);
=================================================
Array
(
[wrapper_data] => Array
(
[0] => HTTP/1.1 200 OK
[1] => Date: Mon, 21 Feb 2011 10:50:27 GMT
[2] => Server: Apache
[3] => Content-disposition: attachment;filename=null.csv
[4] => Content-Length: 0
[5] => Connection: close
[6] => Content-Type: text/plain
)
[wrapper_type] => http
[stream_type] => tcp_socket
[mode] => r
[unread_bytes] => 0
[seekable] =>
[uri] => http://******************************
[timed_out] =>
[blocked] => 1
[eof] =>
)
And what now? How to get the attachment programatically?
|
|
|
|
|
|
|
|
|
|
Re: How to read/to download attachment on an URI? [message #172562 is a reply to message #172557] |
Mon, 21 February 2011 21:44   |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
> Of course, there's also the question as to whether you have permission
> from the site owner to access the information this way; many site owners
> frown on it and will block you if they find out.
Remembering *** STATELESS NATURE OF HTTP *** this frowning looks very
ridiculous and silly. I.e., it's a kind of nonsense to frown on it =)
OK. Now it works. My script is:
===================================================================
$fp = fopen("cURL333.txt", "w");
$ch = curl_init();
///curl_setopt($ch, CURLOPT_URL, "http://stooq.com.ua/q/d/?s=wig20");
////curl_exec($ch);
////$info = curl_getinfo($ch);
///////curl_setopt_array($ch, $info);
curl_setopt($ch, CURLOPT_URL, "http://stooq.com.ua/q/d/l/?
s=wig20&i=d");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'GET http://stooq.com.ua/q/d/l/?s=wig20&i=d HTTP/1.0','Accept: image/
gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-
flash, application/vnd.ms-excel, application/msword, */*','Accept-
Language: ru,zh-cn;q=0.7,zh;q=0.3','Cookie: cookie_uu=110221000;
cookie_user=%3F0001dllg000011500d1300%7Cwig20','User-Agent: Mozilla/
4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)','Host:
stooq.com.ua','Proxy-Connection: Keep-Alive'));
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
================================================================
But I'm a total ***newb*** in PHP and got those headers by some other
way.
How can we get them ***automatically*** after hitting the 1st page???
===============================================
P.S. The saved file looks like this:
===============================================
HTTP/1.1 200 OK
Date: Mon, 21 Feb 2011 21:24:38 GMT
Server: Apache
Content-disposition: attachment;filename=wig20_d.csv
Transfer-Encoding: chunked
Content-Type: text/plain
Date,Open,High,Low,Close,Volume
1991-04-16,100,100,100,100,325
1991-04-23,95.7,95.7,95.7,95.7,5905
1991-04-30,93.5,93.5,93.5,93.5,7162
1991-05-14,92.9,92.9,92.9,92.9,18300
1991-05-21,95.5,95.5,95.5,95.5,14750
1991-05-28,94.6,94.6,94.6,94.6,31440
1991-06-04,95.8,95.8,95.8,95.8,12396
1991-06-11,95,95,95,95,26247
........
........
........
|
|
|
Re: How to read/to download attachment on an URI? [message #172565 is a reply to message #172562] |
Mon, 21 February 2011 22:05   |
Jerry Stuckle
Messages: 2598 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 2/21/2011 4:44 PM, n00m wrote:
>> Of course, there's also the question as to whether you have permission
>> from the site owner to access the information this way; many site owners
>> frown on it and will block you if they find out.
>
> Remembering *** STATELESS NATURE OF HTTP *** this frowning looks very
> ridiculous and silly. I.e., it's a kind of nonsense to frown on it =)
>
Not at all - it is commonly done, and pretty easy - I've done it for
clients who have had their content reused without their permission. It
is also illegal in most (all?) countries.
>
> OK. Now it works. My script is:
> ===================================================================
> $fp = fopen("cURL333.txt", "w");
>
> $ch = curl_init();
>
> ///curl_setopt($ch, CURLOPT_URL, "http://stooq.com.ua/q/d/?s=wig20");
> ////curl_exec($ch);
> ////$info = curl_getinfo($ch);
> ///////curl_setopt_array($ch, $info);
>
> curl_setopt($ch, CURLOPT_URL, "http://stooq.com.ua/q/d/l/?
> s=wig20&i=d");
> curl_setopt($ch, CURLOPT_HEADER, true);
>
>
>
> curl_setopt($ch, CURLOPT_HTTPHEADER, array(
> 'GET http://stooq.com.ua/q/d/l/?s=wig20&i=d HTTP/1.0','Accept: image/
> gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-
> flash, application/vnd.ms-excel, application/msword, */*','Accept-
> Language: ru,zh-cn;q=0.7,zh;q=0.3','Cookie: cookie_uu=110221000;
> cookie_user=%3F0001dllg000011500d1300%7Cwig20','User-Agent: Mozilla/
> 4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)','Host:
> stooq.com.ua','Proxy-Connection: Keep-Alive'));
>
>
>
> curl_setopt($ch, CURLOPT_FILE, $fp);
>
> curl_exec($ch);
> curl_close($ch);
> fclose($fp);
> ================================================================
>
> But I'm a total ***newb*** in PHP and got those headers by some other
> way.
> How can we get them ***automatically*** after hitting the 1st page???
>
> ===============================================
> P.S. The saved file looks like this:
> ===============================================
>
> HTTP/1.1 200 OK
> Date: Mon, 21 Feb 2011 21:24:38 GMT
> Server: Apache
> Content-disposition: attachment;filename=wig20_d.csv
> Transfer-Encoding: chunked
> Content-Type: text/plain
>
> Date,Open,High,Low,Close,Volume
> 1991-04-16,100,100,100,100,325
> 1991-04-23,95.7,95.7,95.7,95.7,5905
> 1991-04-30,93.5,93.5,93.5,93.5,7162
> 1991-05-14,92.9,92.9,92.9,92.9,18300
> 1991-05-21,95.5,95.5,95.5,95.5,14750
> 1991-05-28,94.6,94.6,94.6,94.6,31440
> 1991-06-04,95.8,95.8,95.8,95.8,12396
> 1991-06-11,95,95,95,95,26247
> .......
> .......
> .......
>
>
>
>
As for retrieving the information, if you've got the header info for the
file, you should be able to fetch the file itself with cURL.
But as it's pretty obvious from your answer above that you don't have
permission to do this, sorry, I won't help you.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
|
|
|
Re: How to read/to download attachment on an URI? [message #172585 is a reply to message #172565] |
Tue, 22 February 2011 01:33   |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
Done.
===========================================
<?php
$url_1 = "http://stooq.com.ua/q/d/?s=wig20";
$url_2 = "http://stooq.com.ua/q/d/l/?s=wig20&i=d";
$headers = array(
'GET ' . $url_1 . ' HTTP/1.0',
'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg,
application/x-shockwave-flash, application/vnd.ms-excel, application/
msword, */*',
'Accept-Language: ru,zh-cn;q=0.7,zh;q=0.3',
'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;
SV1)',
'Proxy-Connection: Keep-Alive'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_1);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, $url_2);
$headers[0] = 'GET ' . $url_2 . ' HTTP/1.0';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
$fp = fopen("ccc.txt", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo "\n\n\nDone!\n";
fgetc(STDIN);
?>
|
|
|
|
|
Re: How to read/to download attachment on an URI? [message #172628 is a reply to message #172616] |
Tue, 22 February 2011 15:23  |
n00m
Messages: 25 Registered: February 2011
Karma: 0
|
Junior Member |
|
|
Erwin, of course, you are right.
PHP's fine granularity of control over everything is much more
powerful thing.
It's a senseless idea to compare it against VBA's web/http candies.
> SO it was the Session that was demanded to proceed?
Yes. Precisely in this case it's only cookies and not e.g. REFERER
header.
|
|
|