How to force a file to download (without having to zip it up).
$filename = "secure/writeToFile.doc";
header("Content-Length: " . filesize($filename));
header('Content-Type: application/msword');
header('Content-Disposition: attachment; filename=writeToFile.doc');
readfile($filename);
a few other content types – lots more at the above link…
"pdf": "application/pdf"
"zip": "application/zip"
"xls": "application/vnd.ms-excel"
"ppt": "application/vnd.ms-powerpoint"
"gif": "image/gif"
"png": "image/png"
"jpg": "image/jpg"
"mp3": "audio/mpeg"
"mp3": "audio/mp3"
"wav": "audio/x-wav"
"mpe": "video/mpeg"
"mov": "video/quicktime"
"avi": "video/x-msvideo"
This is one of those things I use all the time but because I can't remember things like this, I always have to look for the exact code to do it…
This will take all the values submitted in a form and store them in a session:
foreach($_POST as $k=>$v) {
$_SESSION[$k]=$v;
}
And when you're ready to dump the [...]
I needed to set the selection of a drop down menu. As far as I can tell, if you don't know the "index" value, then you just have to loop through to set the item as selected. If there's an easier way to do this, please speak up in the comments. I spent WAY too [...]
Because I was having a "duh" moment.
$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]
Problem: (somewhat in line with my last post) I needed to run a script in the "background", but I only had the ability to present the script as a .gif.
Solution: actually, I came up with two ways of doing this and both use .htaccess to pull it off.
1) I'm a gif but really I'm a [...]
Needed to write a javascript that would take the values of one select box – and copy it to all the other select boxes on the same page. I found this script which will take all the values from one set of fields – and copy it to another set of fields (kind of like [...]
I'm in the process of moving a few other blogs over to use WP – one of which makes calls to a seperate database unrelated to WP. This proved to cause a conflict. After many hours of trying to figure out where the specific conflict was – I narrowed it down to my mysql_select_db line. [...]
Since Alex released his js quick tags – it seemed like the perfect thing to add to the comments form so that people could put in the html tags more easily. However, while his script is really powerful – just for the comments form, it's more than what's needed. So I stripped it down to [...]
Just want to store a little javascript snippet. I needed to grey out the text in a text area depending on if a checkbox was checked or not. I'm sure there's a way to get the function to be flexible enough so that it can be passed the specific parameters of WHICH form, WHICH checkbox, [...]