Hello I want to know how can do so that the browsers download the files (for example .txt files, .jpg files e.t.c., besides .php files) and don't open in the browser. Thank you.
Check out following code snippet. You may need to change content-type based on the file type if needed. if(file_exists($file_name)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($file_name)); 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_name)); ob_clean(); flush(); readfile($file_name); exit; } PHP:
Thank you mastermunj. But I've already used this and it works greate: $file = $_GET['file']; header("Content-type: octet/stream"); header("Content-disposition: attachment; filename=".$file.";"); header("Content-Length: ".filesize($file)); readfile($file); exit; PHP: