# Forced download with php

**URL:** https://forum.kirupa.com/t/forced-download-with-php/74409
**Category:** Uncategorized
**Created:** [December 28, 2004, 11:01pm UTC](https://forum.kirupa.com/t/forced-download-with-php/74409 "2004-12-28T23:01:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![fatnslow](https://avatars.discourse-cdn.com/v4/letter/f/7993a0/32.png) [@fatnslow](https://forum.kirupa.com/u/fatnslow)
#### Post date: [December 28, 2004, 11:01pm UTC](https://forum.kirupa.com/t/forced-download-with-php/74409/1 "2004-12-28T23:01:52Z")

</div>

Hey, I got this script for previous posts here on Kirupa:  
PHP Code

```auto
<?php 
$filename = $_GET['filename']; 
if (ereg(".mp3$", $filename)) { 
header("Pragma: public"); 
header("Expires: 0"); 
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header("Content-Type: application/force-download"); 
header("Content-Type: application/octet-stream"); 
header("Content-Type: application/download"); 
header("Content-Disposition: attachment; filename=".basename($filename).";"); 
header("Content-Transfer-Encoding: binary"); 
header("Content-Length: ".filesize($filename)); 
readfile("$filename"); 
} 
?> 

```

Flash Code

```auto
getURL("folder/filedownload.php?filename=someMP3.mp3", "_blank", "GET");

```

How can I use this code to also force download other filetypes, like mp3, wma, avi, rar, zip etc etc…?

Is it any way I just could add the filetype names in the script? Maybe in this part: “if (ereg(”.mp3$", $filename)) {" ???

And how can I get the flash code to be used in the url field in a dynamic textfield? Atm it uses getURL and the has to be used on a button?

If I make any sense, please reply.

Thanks,  
fatnslow
