File Download in PHP

Advertisements

File Upload in PHP Include in PHP

File Download in PHP

Using PHP you can create web page to download file easily using built-in readfile() function. The readfile() function reads a file and writes it to the output buffer.

file download in php

PHP readfile() function

Syntax

int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )  
  • $filename: represents the file name
  • $use_include_path: It is the optional parameter. It is by default false. You can set it to true to the search the file in the included_path.
  • $context: represents the context stream resource.
  • int: It returns the number of bytes read from the file.

Download Text File in PHP

download1.php

<?php

$file_url = 'http://www.your_remote_server.com/f.txt';  
header('Content-Type: application/octet-stream');  
header("Content-Transfer-Encoding: utf-8");   
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");   
readfile($file_url);

?>

Download Binary File in PHP

download2.php

<?php

$file_url = 'http://www.your_remote_server.com/file.exe';  
header('Content-Type: application/octet-stream');  
header("Content-Transfer-Encoding: Binary");   
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\"");   
readfile($file_url);

?>

File Upload in PHP Include in PHP

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements