I have many .csv file in website, Basically i want to know how can i automatic download this file dynamically. In localhost has download folder, In download folder will be download and save auto without mouse/keyboard touch and then i want to do auto import from download folder without mouse/keyboard touch.
Real Fact is , in that website every day will keep .csv file. But everyday software will be auto download and import in MySQL Database without mouse/keyboard touch.
How can i solve it, please detail mention. Really i will be very happy if i get solution to this problem.
Use the following PHP page in your localhost server:
csvsaver.php:
<?php
$saveLocation = 'files';
$urls = array(
'http://yourwebsite/folder/hello.csv',
'http://yourwebsite/csv1.csv'
);
$now = date('Y-m-d_H-i');
$dir = 'files' . '/' . $now;
for ($i = 0; $i < count($urls); $i++){
$url = $urls[$i];
$file = $i . '_' . substr($url, strrpos($url,'/')+1 );
$path = $dir . '/' . $file;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
if (!is_dir($dir)) mkdir($dir);
file_put_contents($path, $data);
}
?>
If for example you put that in 'c:/wamp/www/csvSaver/csvsaver.php', you will also need to create a directory 'files' in it: c:/wamp/www/csvSaver/files/
When you run the above page, it will for example save the two files into:
All you need to do is set up something to run the PHP page daily. If you're using linux, set up a cron job. If you're using windows, set up a scheduled task that runs a .bat file. For an example, Look here. . If that looks too complicated, then just go to your PHP page manually each day.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.