PHP 7 Script to Download Files and Images From URL to Server Using cURL Method 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 curl 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 = '';

// Initialize the cURL session
$ch = curl_init($url);

// Inintialize directory name where
// file will be save
$dir = './';

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

// Save file into file location
$save_file_loc = $dir . $file_name;

// Open file
$fp = fopen($save_file_loc, 'wb');

// It set an option for a cURL transfer
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

// Perform a cURL session

// Closes a cURL session and frees all resources

// Close file


Leave a Reply