Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How do I set up a script to download a file from remote server?
Old 06-23-2006, 03:26 PM How do I set up a script to download a file from remote server?
Webmaster Talker

Posts: 626
Trades: 0
I am looking to write a script which will download a file from a remote server and save it on my server (with hosting company).

I'm looking to setup a cron job which will automatically run everyday at 3am and basically update a file on my server. For example:

Remote Server: Contains file.htm -> Dated June 23, 2006

My Server: Contains file.htm -> Dated June 22, 2006 (out of date)


I want the cron job to download file.htm from the remote server and save it (overwriting) file.htm on my server.

Can someone show me how to do this. I have tried searching for it on google but NO LUCK!
jim.thornton is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-23-2006, 05:00 PM Re: How do I set up a script to download a file from remote server?
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
This should get another file and write it to your file when run.
I haven't tested it or anything i wrote it off the top of my head..

PHP Code:
<?php 
$contents 
file_get_contents('http://url/to/the/file.ext'); //get file
$file "file.htm"// file to write to
$openfile fopen("$file","w+"); // open and truncate file
fwrite($openfile,"$contents");  // write to file
fclose($openfile);  // close the file
?>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Old 06-23-2006, 11:12 PM Re: How do I set up a script to download a file from remote server?
Webmaster Talker

Posts: 626
Trades: 0
thank you... Everything worked perfectly!
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 06-25-2006, 09:56 AM Re: How do I set up a script to download a file from remote server?
daddy2five's Avatar
Skilled Talker

Posts: 77
Name: Daniel
Location: Stony Point , Noth Carolina
Trades: 0
stOx, I was reading this post out of curiosity, I tried your script out to grab a .jpg file of a radar image. Works great! Thanks for posting it. Talkupation for you.
__________________
What is Yuwie?

Please login or register to view this content. Registration is FREE
daddy2five is offline
Reply With Quote
View Public Profile Visit daddy2five's homepage!
 
Old 06-26-2006, 08:53 AM Re: How do I set up a script to download a file from remote server?
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Does it work around htaccess hot linking ?

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 06-26-2006, 09:22 AM Re: How do I set up a script to download a file from remote server?
daddy2five's Avatar
Skilled Talker

Posts: 77
Name: Daniel
Location: Stony Point , Noth Carolina
Trades: 0
I just pointed the script to the .jpg file url and renamed a few things and it works like a charm.
__________________
What is Yuwie?

Please login or register to view this content. Registration is FREE
daddy2five is offline
Reply With Quote
View Public Profile Visit daddy2five's homepage!
 
Old 06-26-2006, 10:22 AM Re: How do I set up a script to download a file from remote server?
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
Yes this method is a workaround for hotlinking

Read in the img contents and spit out the relevant headers then echo the img to screen. Its not adering to the htaccess hotlink prevention.

So htaccess hotlinking prevent direct (img src="") calls but you can alsways grab the image contents and spit them out.

Not that I am into hotlinking or what have you, just nice to know work arounds for everything.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 06-26-2006, 11:09 AM Re: How do I set up a script to download a file from remote server?
daddy2five's Avatar
Skilled Talker

Posts: 77
Name: Daniel
Location: Stony Point , Noth Carolina
Trades: 0
I just used the script to bring the file to my server then used <img src=""> and pointed it to my file. I see what you are talking about though.
__________________
What is Yuwie?

Please login or register to view this content. Registration is FREE
daddy2five is offline
Reply With Quote
View Public Profile Visit daddy2five's homepage!
 
Old 06-26-2006, 04:17 PM Re: How do I set up a script to download a file from remote server?
Webmaster Talker

Posts: 626
Trades: 0
What exactly is htaccess hotlinking?
jim.thornton is offline
Reply With Quote
View Public Profile
 
Old 06-28-2006, 09:13 AM Re: How do I set up a script to download a file from remote server?
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
htaccess can prevent other people from hijacking your bandwith by (HOTLINKING) linking to your images. htaccess can issue a different image stating your nicking other peoples images or it simply prevents the image been accessed resulting in a broken image.

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 06-28-2006, 05:53 PM Re: How do I set up a script to download a file from remote server?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Definition of Hotlinking
posted from: http://www.free-webhosts.com/definition/hotlinking.php

"Hotlinking" (also called "hot linking", "leeching", and "bandwidth theft") is a term referring to when a web page of one website owner is direct linking to the images or other multimedia files on the web host of another website owner (usually without permission, thus stealing bandwidth). This not only causes the other person to pay for the bandwidth of the hotlinked file, but often is intellectual property theft. The term is also used loosely (a misnomer) by free image hosts which allow you to store images on their server and allow you to direct link the hosted image files on forums or other websites (sometimes altering the image to have a watermark). One of the most common occurrences of "hot linking" is when people are forum posting and they hotlink pictures from another website to use as avatars or signature images on the messageboards (forums). Some disadvantages of hot linking worth considering are that the webpage generally loads slower when you link to images stored on a different web hosting server than the webpage is hosted on, and the owner of the image has full control to disable hotlinking, or delete, rename, or worse yet, do a "switcheroo" (i.e., switching the file name to be another image which is sure to cause the hotlinker embarrassment) of the hot-linked image. Common methods of preventing hotlinking are by using an .htaccess file, using the "Hotlink Protection" offered in control panels such as Cpanel, or simply renaming image files periodically.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-28-2006, 06:51 PM Re: How do I set up a script to download a file from remote server?
daddy2five's Avatar
Skilled Talker

Posts: 77
Name: Daniel
Location: Stony Point , Noth Carolina
Trades: 0
I dont believe that what i am doing is hotlinking. I am simply copying the image over to my server. I <img src="file.jpg"> and point it to my copied img file. So I am hosting the img. Is that wrong? If so I will take it down.
__________________
What is Yuwie?

Please login or register to view this content. Registration is FREE
daddy2five is offline
Reply With Quote
View Public Profile Visit daddy2five's homepage!
 
Old 06-28-2006, 07:04 PM Re: How do I set up a script to download a file from remote server?
cpfreak23's Avatar
Super Talker

Posts: 143
Trades: 0
In my opinion its not wrong. I mean you could be directly linking to the image file, @ least this way you're only getting the image information once per day (maybe less) instead of each time someone views your page.
cpfreak23 is offline
Reply With Quote
View Public Profile
 
Old 06-29-2006, 11:44 AM Re: How do I set up a script to download a file from remote server?
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
Trades: 0
I agree if your grabbing the image just the once, but if you do a grab like that each time its requesrted then I suppose it could be seen as hotlinking (or certainly bandwidth theft).

Ibbo
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Linux user #349545 :
(GNU/Linux)iD8DBQBAzWjX+MZAIjBWXGURAmflAKCntuBbuKCWenpm XoA7LNydllVQOwCf
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 06-29-2006, 01:18 PM Re: How do I set up a script to download a file from remote server?
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
Heres a small tutorial i wrote on How to prevent hotlinking if anyone is interested.

For the most part hotlinking doesn't bother me too much, If someone posts an image from my server on a forum i don't mind. But if they use my images for thier site theme and are stealing bandwidth then i usually take action.
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Old 06-29-2006, 09:57 PM Re: How do I set up a script to download a file from remote server?
Novice Talker

Posts: 7
Trades: 0
There is definately something wrong with hotlinking.
__________________

Please login or register to view this content. Registration is FREE
kcraig11388 is offline
Reply With Quote
View Public Profile
 
Old 06-30-2006, 10:36 AM Re: How do I set up a script to download a file from remote server?
Extreme Talker

Posts: 170
Name: XpIndia.Com
Trades: 0
Can this script be used to read contents of a .php file ?
__________________

Please login or register to view this content. Registration is FREE

Server alert/reseller-
Please login or register to view this content. Registration is FREE
XpIndia.Com is offline
Reply With Quote
View Public Profile
 
Old 06-30-2006, 10:42 AM Re: How do I set up a script to download a file from remote server?
stOx's Avatar
Machine

Latest Blog Post:
Worlds Smallest Car - Peel P50
Posts: 2,111
Name: Matt. (>',')>
Location: London, England.
Trades: 0
No it can't. Why would they make it possible to read the contents of a php file? It would make security nonexistant..
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
stOx is offline
Reply With Quote
View Public Profile Visit stOx's homepage!
 
Reply     « Reply to How do I set up a script to download a file from remote server?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.87018 seconds with 12 queries