我想每天下午5点下载“Bhavcopy.cvs”文件格式“nseindia.com”。
所以,我想要从“nse”网站自动下载此文件的php代码...
请帮忙
我尝试了以下代码。
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename=http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv.zip');
header('Pragma: no-cache');
readfile("http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv
答案 0 :(得分:0)
答案 1 :(得分:0)
使用file_get_contents非常简单,您可以将文件加载到变量中。如果已启用fopen包装器。您可以使用str_getcsv解析结果。
$data = str_getcsv(file_get_contents('http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv'));
如果您需要设置特定标题,请使用其他 delimeters manualy 。
如果您拒绝访问,请添加以下标头参数。
$fname = "nsecsv";
header('HTTP/1.1 200 OK');
header('Cache-Control: no-cache, must-revalidate');
header("Pragma: no-cache");
header("Expires: 0");
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=$fname");
readfile('http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv');
$url = 'http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv';
curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec($ch);
curl_close($ch);
检查这个很棒的cURL纪录