1

my task is easy but I can't find anything on the web to help me.

I click on a button on my website, this event execute a php file (by ajax).

In this php file, I want to download a csv files directly on my serveur in the folder /uploads. I have the link of the csv, exemple : www.thewebsite.com/files/yourlastcall.csv

I have access to this folder, and I have all the rights in my /uploads.

So, do you guys know how to achieve this?

Thank you, and sorry for my english, i'm a little frenchy :)

Peter
  • 1,719
  • 4
  • 22
  • 31
  • And if I can change the name of the file, it will be just perfect :) – Peter Jun 18 '13 at 17:36
  • 1
    Checkout: [file_get_contents](http://php.net/file_get_contents). – phpisuber01 Jun 18 '13 at 17:39
  • I dont think its possible with AJax...see here....this will definitely help you... http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax – Kylie Jun 18 '13 at 17:39
  • Kylek, I don't want to move the file on the computer of the client ;-) See the answer of Joel above this topic. – Peter Jun 18 '13 at 17:47

2 Answers2

4

Something like this, maybe?

$url = 'http://website.com/linktofile.csv';
$source = file_get_contents($url);
file_put_contents('/path/to/file/newfilename.csv', $source);

Edit: Of course, that's just the PHP part. I'm assuming you know how to make an AJAX call already, in jQuery or similarly.

Joel Hinz
  • 24,719
  • 6
  • 62
  • 75
  • Sound's Awesome, and yes the rest of the task I am ok with it :) I will accept your answer in 10mins ! – Peter Jun 18 '13 at 17:41
0
$url = 'http://website.com/linktofile.csv';
$source = file_get_contents($url);
file_put_contents('/path/to/file/newfilename.csv', $source);

thanks to Joel Hinz

Peter
  • 1,719
  • 4
  • 22
  • 31