ADVERTISEMENT
ADVERTISEMENT

PHP program to download the text file from the specified URL

Here, we are going to learn how to download the text file from the specified URL in PHP?
Submitted by Nidhi, on November 22, 2020

Here, we will demonstrate how we can download a text file from a specified URL using the PHP program.

Program/Source Code:

The source code to download the text file from the specified URL is given below. The given program is compiled and executed successfully.

<?php
//PHP program to download the text file.
$download_url = 'http://www.includehelp.com/sample.txt';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: utf-8");
header("Content-disposition: attachment; filename=\"" . basename($download_url) . "\"");
readfile($download_url);
?>

Explanation:

Here, we created a variable $download_url that contains the file URL that will be downloaded. After that, we prepared the header and call readfile() to download the file.

More PHP Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.