FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


File grab script? Will pay 30 FRIH$





[FuN]goku
Right... is it possible to grab a file from another site via php...
like grab an exe and store it on your own webserver, if you think about it, its like the wget function on linux, thats what i need it to do, so i dont have to upload large files to my webserver ( not frihost one )

Thanks in advance
MrBlueSky
Code:

<?php

  function getfile($source, $dest) {
 
     $fr = fopen($source, "rb");
     $fw = fopen($dest, "w+b");
     while (!feof($fr)) {
        $str = fread($fr, 8192);
        fwrite($fw, $str);
        echo ".";
    }
    fclose($fr);
    fclose($fw);
   
  }
 
  getfile("http://www.site.com/pathto/somefile.exe", "/pathto/local/file.exe");
 
?>



Let me know what additional features you want.
[FuN]goku
ahh ok, it works for a certain extent for me... I have to create the file name before hand on the server then execute the script otherwise i get fopen/fwrite errors.. but it works so ill send you 30 FRIH$ now ^^
[FuN]goku
actually do you think you can add a feature to tell the % downloaded? or something like that and xxx KB/ xxx KB downloaded or somthing. will pay an additional 50 FRIH$
MrBlueSky
[FuN]goku wrote:
ahh ok, it works for a certain extent for me... I have to create the file name before hand on the server then execute the script otherwise i get fopen/fwrite errors..


Then you probably want to write the file to a directory to which apache doesn't have write permissions.


[FuN]goku wrote:
actually do you think you can add a feature to tell the % downloaded? or something like that and xxx KB/ xxx KB downloaded or somthing. will pay an additional 50 FRIH$


I will see what I can do.

(For anybody wondering why I didn't use get_file_contents: To not hog the virtual memory of the server to which the file is downloaded)
[FuN]goku
MrBlueSky wrote:
[FuN]goku wrote:
ahh ok, it works for a certain extent for me... I have to create the file name before hand on the server then execute the script otherwise i get fopen/fwrite errors..


Then you probably want to write the file to a directory to which apache doesn't have write permissions.

EH? wot u mean by that?
MrBlueSky
[FuN]goku wrote:

EH? wot u mean by that?


Linux uses 'permissions' to manage which user and which program can do something with a file or a directory.

You can try setting the permissions of the directory you save the files on your server to '777' (readable and writable for everyone, only use as temporary directory not to store anything important). I don't know how you can do that, because I don't know what kind of managemant panel your host has, but here you can read how you do that using Directadmin at Frihost: http://www.site-helper.com/filemanager.html#permissions
[FuN]goku
ahh so just chmod the folder to 777 then? easy enuff...
and my host has cPanel ^^


EDIT: Yeah chmoding the folder works fine ^^ thanks for that bit of info.
MrBlueSky
Where do you let the script download from? HTTP or FTP?
[FuN]goku
http.
MrBlueSky
In that case it is not possible to get the file size before you start downloading, so it is not possible to add a counter which expresses which percentage is downloaded. I can add a counter which displays how many MB's are downloaded.
[FuN]goku
MrBlueSky wrote:
In that case it is not possible to get the file size before you start downloading, so it is not possible to add a counter which expresses which percentage is downloaded. I can add a counter which displays how many MB's are downloaded.
good nuff then.
MrBlueSky
Oke, here it is:

Code:

<HTML>
  <HEAD></HEAD>
  <BODY>

   
<?php

  function getfile($source, $dest) {

     ?>
     
    <SCRIPT type='text/javascript'>
      
   
    <?php
     $fr = fopen($source, "rb");
     $fw = fopen($dest, "w+b");
     $count = 0;
     while (!feof($fr)) {
        $str = fread($fr, 8192);
        fwrite($fw, $str);
        $count += mb_strlen($str);
        echo "document.body.innerHTML = '$count bytes downloaded..';\n";
        echo "</SCRIPT><SCRIPT type='text/javascript'>\n";
      }
   
    fclose($fr);
    fclose($fw);
    ?>
    document.body.innerHTML = 'Done!';
    </SCRIPT>
   
  <?php
   
  }
 
  getfile("http://www.site.com/file.ext", "some.file");
 
?>

</BODY>
</HTML>
Related topics
Will Pay 60 Frihs for an Excellent Flash Intro to my site.
Will pay 15 frih$ for banner
[CLOSED] Banner contest, win 30 frih$
Math Problem. 30 frih. (Solved!)
Paying $30 for mods installation!!
Will pay 75 frih$ to setup phpbb
25-30 frih$ for upload of MyBB {<(CLOSED)>}
Review My Site and Get 10-30 Frih$
Add Translation to Your Site and Get 30 Frih
30 frih$ for an affiliate
30 frih$ for a photoshop
Super fast script mod (300 frih)
Need del.icio.us [EARN 30 frih$]
30 Frih$ For Business Cards
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.