How to download a php file without executing it?

Viewed 67646

im working on a content management system for that i have to download a php file using php code without executing. any one can help me on this

it is some thing like ftp. i have added the options to upload, edit and download a file. it is working fine. but while downloading a php file it is executed instead of downloading...

What i tried is:

<?php
$file = $_REQUEST['file_name'];

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));

    include_once($file);
    exit;
}
?>
6 Answers

if someone is looking to do this in his/her .htaccess file:

Header set Content-Disposition attachment
AddType application/octet-stream .php

or

<FilesMatch "\.(?i:php)$">
  ForceType application/octet-stream
  Header set Content-Disposition attachment
</FilesMatch>
Related