About a month ago I wrote a script for my own need. It can download files from another server to your server. I just wrote it for my own purpose and it’s pretty simple and stupid enough. But hey, it works 😉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
<?php if (isset($_POST['sub'])) { if (filter_var($url = $_POST['url'], FILTER_VALIDATE_URL)) { define('UPLOAD_DIR', dirname(__FILE__) . '/files/'); $length = 5120; $handle = fopen($url, 'rb'); $filename = UPLOAD_DIR . substr(strrchr($url, '/'), 1); $write = fopen($filename, 'w'); while (!feof($handle)) { $buffer = fread($handle, $length); fwrite($write, $buffer); } fclose($handle); fclose($write); echo "<h1>File download complete</h1>"; } else { echo "<h2>Invalid url</h2>"; } } ?> <form action="" method="POST"> <p> <label for="url">Url:</label> <input type="text" size="50" name="url" id="url" /> </p> <p> <input type="submit" name="sub" value="download" /> </p> </form> |
This script has a form input field to make the operation simpler. The downloaded files will be saved on a directory named /files. I am just sharing it, may be it will help you in anyways 🙂
A great work again. I am searching a long time for a tool tike this. But one question. Will it work on Shared hosting?
This is a simple php file read/write operation. It’ll work anywhere I think.
Thanks for sharing. It’s an essential code that sometimes I needed.
its not working continiusly getting error “Invalid url”
thank you
Thanks, this worked well
When I enter the URL, i am getting the message file download complete but file is not being downloaded. Which path do I need to change in order to see the file?? Thanks
Parse error: syntax error, unexpected T_STRING in line 5 please help
that dosent work with google drive
Nice script… more useful to me… thanks alot bro…
Great job! Simple yet powerful.
I am a newby to php so could you please help
Which fields do I need to fill and does the script create the files folder
Thanks
So, just one simple script – it works perfect for me! TY 😉
Works AWESOME … Great work