php code to download a .txt file on a url ?

mic141414

Power Member
Joined
Jul 3, 2008
Messages
518
Reaction score
166
Hey,

Anyone with php knowledge could make that for me ? (or charge me a few $)

I will have 2 or more sites with a txt file (http://blablable.com/filetext.txt, http://blablabla2.com/filetext.txt, etc )
Lets say that these sites won't be up for long
I need to be able to save those txt files at regular interval so i don't lose the info in case site got shut down.
The txt file will be modified each time a surfer enters the info i need.

So with each save, the txt can be overwrite .. but need to be sure that in case it becomes 404 or not reachable, the latest saved is kept and not written with a blank file

Let me know thanks in advance

PS: i tried in crontab like this wget -O /tmp/filetext.txt http://blablable.com/filetext.txt it wont work .. target size file is 0 and nowhere to found in server where the cron runs. Need a small php app please
 
I'm not sure but I dont think u need php for that, you can in bash. Is tha first line of text file always the same?
 
Are you able to view those TXT files in the browser in first place ?

If they are protect with htaccess you will only be able to get it from FTP
 
yes able to see them in the browser and not htaccess protected


Are you able to view those TXT files in the browser in first place ?

If they are protect with htaccess you will only be able to get it from FTP
 
Then the file probably needs useragent or referrer to allow u to download or view it and with that wget command it does not define it.

Try adding these to your wget command:

Code:
--referer='http://domain.com'

And:

Code:
--user-agent='Mozilla/4.0 (Windows; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)'
 
okay thanks i am gonna try
thanks for your help
 
try to use a download trigger something like this and run it in your browser


Code:
trigger.php

[COLOR=#0000BB][FONT=monospace]<?php 
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// shouldn't this supress output to the browser?: 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Header[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Content-Type: application/x-octet-stream"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);  
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// filename for download: 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Header[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]""[/FONT][/COLOR][COLOR=#007700][FONT=monospace]);  
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// dump URL: 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loc[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]""[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; 
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// open location: 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$fp[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]fopen[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$loc[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"r"[/FONT][/COLOR][COLOR=#007700][FONT=monospace]); 
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// read contents: 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$content[/FONT][/COLOR][COLOR=#007700][FONT=monospace]=[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]fread[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$fp[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]100000000[/FONT][/COLOR][COLOR=#007700][FONT=monospace]); 
[/FONT][/COLOR][COLOR=#FF8000][FONT=monospace]// output: 
[/FONT][/COLOR][COLOR=#007700][FONT=monospace]echo [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]$content[/FONT][/COLOR][COLOR=#007700][FONT=monospace]; 
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]?>
[/FONT][/COLOR]


or CURL


set_time_limit([COLOR=#800000]0[/COLOR]); [COLOR=gray]// unlimited max execution time[/COLOR]$options = array(  CURLOPT_FILE => [COLOR=#800000]'/path/to/download/the/file/to.zip'[/COLOR],  CURLOPT_TIMEOUT => [COLOR=#800000]28800[/COLOR], [COLOR=gray]// set this to 8 hours so we dont timeout on big files[/COLOR]  CURLOPT_URL => [COLOR=#800000]'big/file.zip'[/COLOR],);$ch = curl_init();curl_setopt_array($ch, $options);curl_exec($ch);
 
Back
Top