从特定网站自动下载.csv文件。

I want to download "Bhavcopy.cvs" file form "nseindia.com" on everyday at 5 pm.

So, I want php code that automatic download this file from "nse" website...

Please help

I tried following code.

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

Use php's native CURL function to fetch pages from various resources

Documentation: https://php.net/manual/en/function.curl-exec.php

Use a Cronjob to schedule the php script daily.

Very simple way you use file_get_contents, you can load a file into a variable. if the fopen wrappers have been enabled. You can parse the result with str_getcsv.

$data = str_getcsv(file_get_contents('http://www.nseindia.com/products/content/equities/equities/homepage_eq.htm/cm07APR2014bhav.csv'));

If you need to set specific headers you use an other delimeters manualy.

If you getting access denied add following header parameter.


readfile() function

    $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');

cURL function

$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);

Check this great cURL documetation