0

I want to download a csv file using a link automatically in a specified folder by running a cron job using PHP.

I tried the below code ,but it gets downloaded in download folder by default.

can any one show me the right way to do it.The code used is below.

$link="http://labcase.com/wrt/search.php?format=csv&sortby=reqnum|DESC&Search=non_closed_req&state[]=New&state[]=Pending%3A+Delivery&state[]=Pending%3A+Installation&state[]=On+Hold&state[]=Pending%3A+More+Info&state[]=Assigned&state[]=Working&state[]=Pending%3A+Approval&orgs[]=125&orgs[]=25&bldg[]=BGL04%2CBGL11%2CBGL12%2CBGL13%2CBGL14%2CBGL15%2CBGL16%2CBGL17%2CBGL20%2CBGL22%2CBGL25%2CBGL26%2CBGL43&business_unit=all";
header('Content-Disposition: attachment; filename=example.csv');
header("Content-Type: application/force-download");
header('Pragma: no-cache');
readfile($link);
Sal00m
  • 2,938
  • 3
  • 22
  • 33
user_conquer
  • 21
  • 2
  • 5
  • Sounds like a browser security issue. If it were possible for the script to pick the download folder, evildoers would rejoice. Therefore, the browser is designed not to do that. – Paul Oct 08 '14 at 07:45
  • When you are using Cron Job, does it will work? You are not using browser from Cron Job, but CLI, so there will be no popup to save file. – Justinas Oct 08 '14 at 07:49
  • How will running a Cron Job on the server cause files to magically appear on the client? – Paul Oct 08 '14 at 07:55

1 Answers1

1

You can use this:

file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));

Take a look here

Community
  • 1
  • 1
Dan
  • 863
  • 2
  • 23
  • 43