I am writing a script in which i have to fetch a file and save it to the server on which the script is running . I have Googled it a lot but can not find how it can be done.

I once again try to explain, i want to get a file from a remote url to save on a server. Let us say that the file is text file located at some url exampleone.com/newpicture.jpg i want to download it to my site www.exampletwo.com

How can this be done.

Thanks in advance.

8 Years
Discussion Span
Last Post by diafol

I think I already gave a solution to this using the php copy() function.


Yeah i know but it is not working for me.. I have tried to send the url to the download.php file but it does not works.

Actually it is a dynamic url, i am looking for a solution, it is not compulsary that it should be solved in php.

I want to download the Google trends CVS to the webserver but when i give its url to your quoted download.php file nothing happens.

the url to Google trends csv is


Now i send it to download php like this


but nothing happens and it gives error.. I will be really very very thankful if you can guide to a proper way.



I think the problem with your request is that the google address doesn't point to a physical file - the querystring dynamically creates the file and forces a download. I'll have a look, but I'm not sure there is a simple solution.

How about this? It tells me that I have to be logged in to use it (the info within the file I mean).

$ch = curl_init("http://www.google.com/trends/viz?q=check+it+out&graph=all_csv&scale=1&sa=N");
$fp = fopen("googlecsv.csv", "w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);



Edited by diafol: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.