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
| 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.
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 ^^
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$
| [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)
Last edited by MrBlueSky on Sun Mar 04, 2007 7:47 pm; edited 1 time in total
| 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?
| [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
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.
Where do you let the script download from? HTTP or FTP?
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.
| 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.
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>
|