PHP 7 Script to Download Files and Images From URL to Server Using file_get_contents() Function Full Project For Beginners

  • Post author:
  • Post category:PHP
  • Post comments:0 Comments


Welcome folks today in this blog post we will be downloading files and images from url to server using file_get_contents() method in php 7.All the full source code of the application is shown below.




Get Started




In order to get started you need to make an index.php file and copy paste the following code








// Initialize a file URL to the variable
$url = '';

// Use basename() function to return the base name of file
$file_name = basename($url);

// Use file_get_contents() function to get the file
// from url and use file_put_contents() function to
// save the file by using base name
if(file_put_contents( $file_name,file_get_contents($url))) {
    echo "File downloaded successfully";
else {
    echo "File downloading failed.";


Leave a Reply