Jump to content

Automatic download?


Cragsterboy

Recommended Posts

 

Hey,

 

ive just started getting into php, so yeh im a bit of a noob at the moment.

 

But i was wondering, is there a script which automatic downloads a file from another server to its own server ???

 

So like every twenty four hours (becuase the data i want to download updates every 24 hrs) it downloads the file to its server?

 

Ive had a look around but all im finding is scripts to force users to download which i dont want, so yeh if there is a script could you help me out with it?

 

Thanks,

 

~Crag

Link to comment
Share on other sites

What is the file you're going to "download"? You could use file_get_contents, and then file_put_contents.

 

The file i want to download is a txt file, but its in urlencode() so when it downloads i need it to decode it as well, so i will have to find a script to do that as well, i did find a decoder script earlier but lost, but il find ti again in a moment. Do you have any tips or tricks for decoding it?

 

K ive just done a quick script with the two things you suggested, im guessing its wrong

 


<?php
echo file_get_contents("www.test.com/test.txt");
echo file_put_contents("test.txt","www.test.com/test.txt");

?> 

 

Am i on the correct lines there?

 

~Crag

Link to comment
Share on other sites

No, your code needs to be

<?php

$contents = file_get_contents("http://www.test.com/test.txt");
if(!empty($contents))
{
    file_put_contents("test.txt", $contents);
}

?>

 

The file i want to download is a txt file, but its in urlencode() so when it downloads i need it to decode it as well

Do you mean it encoded using urlencode()? If so PHP has built function called urldecode() to decode the urlencode'd string.

Link to comment
Share on other sites

<?php

$contents = file_get_contents("http://www.test.com/test.txt");
if(!empty($contents))

$a = explode('&', $QUERY_STRING);

foreach($a as $key => $b)
{
   $b = split('=', $b);
   echo 'Value for parameter '.htmlspecialchars(urldecode($b[0])).' is '.htmlspecialchars(urldecode($b[1]))."<br />\n";
} 

{
    file_put_contents("test.txt", $contents);
}

?>

 

Ok ive added the code to decode the urlencode(), im guessing again that code above is wrong lol as you can see iam a bit of a noob with php lol SO yeh sorry for the annoyance lol

 

~Crag

Link to comment
Share on other sites

WHat that! What's supposed to be encoded? The file url or the contents of the file? If its the contents of the file then its

<?php

$contents = file_get_contents("http://www.test.com/test.txt");
if(!empty($contents))
{
    $contents = urldecode($contents);
    file_put_contents("test.txt", $contents);
}

?>

Link to comment
Share on other sites

WHat that! What's supposed to be encoded? The file url or the contents of the file? If its the contents of the file then its

<?php

$contents = file_get_contents("http://www.test.com/test.txt");
if(!empty($contents))
{
    $contents = urldecode($contents);
    file_put_contents("test.txt", $contents);
}

?>

 

Lol that made me laugh, see told you i was wrong (a large amount wrong) I was reading the link you gave me and it said that the code i put in was the right code and more cleaned up so i guess i was wrong lol.

 

Ok right im guessing now i need to do a cron job? So that it executes this script daily? Am i correct there? for once? lol

 

~Crag

Link to comment
Share on other sites

whay go me.

 

Right i just used the script and it worked, except it didnt decode the text, so i change the chmods on it to 777, because i thoguht it was due to it not being able to execute and now my script wont work  ??? ive changed the chmods back and still no luck heres my script below

 

<title>Auto download</title>

<?php

$contents = file_get_contents("http://en8.tribalwars.net/map/tribe.txt");
if(!empty($contents))
{
    $contents = urldecode($contents);
    file_put_contents("world8.txt", $contents);
}

?>

 

ok now its showing this

 

The server encountered an unexpected condition which prevented it from fulfilling the request.

The script had an error or it did not produce any output. If there was an error, you should be able to see it in the error log.

 

What am i doing wrong now? lol

 

~Crag

Link to comment
Share on other sites

Check your servers error log, the reason for the error will be logged there.

 

Also you'll need to make sure the file world8.txt has write permissions (chmod 755 should do it). I am also amusing you're running php5, as file_put_contents is only available for PHP5. You can check the version of PHP by running phpversion() function.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.