Skip to main content

Posts

Showing posts from November, 2022

PHP script to download file from specific folder

Below is a simple example of a PHP script that allows you to download file from a specific folder. You can link to this PHP file with the file name as a parameter. Create a file named download.php and add the following code: <?php // Specify the folder where your files are stored $folderPath = '/path/to/your/files/' ; // Get the file name from the query parameter if ( isset ( $_GET [ 'file' ])) { $fileName = basename ( $_GET [ 'file' ]); $filePath = $folderPath . $fileName ; // Check if the file exists if ( file_exists ( $filePath )) { // Set headers for download header( 'Content-Description: File Transfer' ); header( 'Content-Type: application/octet-stream' ); header( 'Content-Disposition: attachment; filename="' . $fileName . '"' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate' ); header(