Q:

PHP program to download the text file from the specified URL

belongs to collection: PHP Miscellaneous

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

PHP Miscellaneous

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
PHP program to demonstrate the use of $GLOBALS to ... >>
<< PHP program to send an HTML email message...