scriptygoddess

Archive for the ‘Script snippet’ Category

09 Feb, 2007

Force File Download

Posted by: Jennifer In: Bookmarks| PHP Related| Script snippet| Scripts

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 [...]

29 Jan, 2007

Get current URL with PHP

Posted by: Jennifer In: Script snippet

Because I was having a "duh" moment.
$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

19 Oct, 2004

gifs that execute a php script

Posted by: Jennifer In: Lessons learned| Script snippet

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. [...]

10 Jun, 2004

Quick Tags for comments

Posted by: Jennifer In: Script snippet| WordPress

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 [...]

02 Jun, 2004

Random with MySQL

Posted by: Jennifer In: Script snippet

Guest Authored by
Michelle – usr-bin-mom.com/

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, [...]


Featured Sponsors


  • Michael: You can use get_header(2) in your case. The filename of your custom header has to be header-2.php. The problem with include(your_file.php) is, all
  • cliff: hi wonder if you can help me, pls i designed www.kouga.mobi using dreamweaver CS3 and now want to make the phonenumbers into links so that if you
  • jerey: how do i rewrite this because it tried RewriteEngine on #Options +FollowSymlinks RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FIL

About


Advertisements