Skip to content

ThirteeNov

My personal blog about coding and internet

Menu
  • About me
  • About Zofia Kreasi
  • Cart
  • Checkout
  • Making an airplane game from scratch in Unity
  • My account
  • Privacy Policy
  • Privacy Policy – zkLeaderboard
  • Sample Page
  • Shop
  • Tutorials on Learning JavaScript
  • ZKAccounts – Privacy Policy
Menu

PHP File Downloader

Posted on November 5, 2020November 8, 2020 by Habibie

It is a simple PHP program to download any file from URL to your server

Let’s say we have two websites, the old one has some files that we need to move them or copy them to the second website. Obviously we can download those files from 1st website and upload them to 2nd website. But, with this simple PHP program, we can move the files between those two without downloading them and uploading again.

The way it works is very simple, first you need to specify a file url which you want to download, and second specify a folder/directory where you want the downloaded file to be there (leave it empty if you want to download the file on the root directory). Then click the download button. Done!

Here it is:

<!DOCTYPE html>
<html>
    <head>
        <title>PHP File Downloader</title>
    </head>
    <body>
        
        <?php
        if(isset($_POST["url"])){
            $url = $_POST["url"]; 
            $directory = $_POST["directory"];
            
            if($url != ""){
                
                $dirname = "";
                
                if($directory != ""){
                    if(!file_exists($directory))
	                    mkdir($directory);
	                $dirname = $directory . "/";
                }
                
                $file_name = $dirname . basename($url); 
                   
                if(file_put_contents( $file_name,file_get_contents($url))) { 
                    echo "File downloaded successfully"; 
                }
                else { 
                    echo "File downloading failed."; 
                } 
            }
        }
        ?>
        
        <h1>PHP File Downloader</h1>
        <p>This program will help you to download a file from any url to a directory inside your server</p>
        <form method="post">
            <label>File URL to download</label>
            <input name="url">
            <label>Target Directory</label>
            <input name="directory">
            <input type="submit" value="Download">
        </form>
    </body>
</html>
Post Views: 296
ciihuy2020

Welcome!

  • My YouTube Channel
  • My GitHub Page
  • About me

Categories

  • 3DVista
  • Android
  • Apache
  • C#
  • Cordova
  • Electron & Node JS
  • HTML5, CSS & JavaScript
  • iOS
  • Let's Make Unity Games
  • Misc
  • Photoshop
  • PHP
  • Python
  • Uncategorized
  • Unity
  • WordPress

Recent Posts

  • Make objects like wires and cables easily in Unity using Ciihuy Curved Mesh
  • [SOLVED] Can’t Add Custom Domain to Blogger After Losing CNAME Verification
  • iOS App Icon Generator by CiihuyCom
  • Advanced Blinking Marker Script to show objects position in your game canvas
  • Ciihuy Images Merger – Fast & Easy Online Image Combiner
© 2025 ThirteeNov | Powered by Superbs Personal Blog theme