scriptygoddess

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"

08 Feb, 2007

PHP if statement in shorthand

Posted by: Jennifer In: Bookmarks

Another "tired of hunting for the exact syntax" things… Here's shorthand for an "if" statement:

echo isset($var) ? $var : "sorry, nothing here";

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 session values…

session_unset();// reset session array
session_destroy(); // destroy session.

07 Feb, 2007

Stubborn IE list-stlye

Posted by: Jennifer In: Bookmarks

So my latest CSS fight, with which browser? IE, of course!

I was updating someone's site, and set up a new "side menu" type navigation. I set it up as an unordered list using images for bullets, because I wanted them to change on :hover (and we know that IE will not listen to any :hover descriptions that is not an anchor (a) type). Easy enough:

.maincontent .sidemenu ul {
margin:0;
padding: 5px 0 0 0px;
list-style: none;
list-style-type:none;
}

.maincontent .sidemenu ul li {
padding: 0 0 10px 0;
margin: 0 0 0 10px;
list-style: none;
list-style-type: none;
}

.maincontent .sidemenu ul li a {
color: #000;
padding: 0 0 0 15px;
display: block;
background: url('/images/arrow-red.gif') left 4px no-repeat;
}

.maincontent .sidemenu ul li a:hover {
color: #D43D2B;
background: url('/images/arrow-black.gif') left 4px no-repeat;
}

(the padding, etc was for styling)… Looks great in Firefox, but load the page up in IE, and mysteriously, the bullet for the lists was still there…

Finally, I thought it was odd that the list-style was even stylized somewhat instead of a plain old bullet… hunted down in some of the other stylesheets of the site and noticed that there was a universal definition for UL and even though I was trying to "override" it in my stylsheet… it refused to do so in IE:

UL { list-style: circle; }

Changing that to be specific for the container it was in (which was not the sidemenu) fixed the problem…

.othercontentdiv UL { list-style: circle; }

Comments Off on Stubborn IE list-stlye

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 long hunting for a better solution, but this was the only thing that worked:

for (var i=0; i < document.formname.dropdownboxname.length; i++) {
if (document.formname.dropdownboxname[i].value == "value") {
document.formname.dropdownboxname[i].selected = true;
}
}

Update Posting my comment in the main post – because this is the way to do it right: Use jQuery because it rules.

Use this plugin:
http://www.texotela.co.uk/code/jquery/select/

And this code:
$(document).ready(function() {
$(”#selectboxname”).selectOptions(”The Select Value”, true);
});

05 Feb, 2007

Firefox???

Posted by: Jennifer In: Bookmarks

Is it just me or with the last update to Firefox has it been… uhm.. particularly buggy? I've had it crashed more than ever before, and it's just… slow… I used to LOVE firefox. But this is getting pretty annoying. I don't have an outrageous number of addons/extensions running, but I might try turning them off (then back on one at a time) to see if that helps… Anyone else having issues? (I'm using ver 2.0.0.1)

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"]

From Javascript Get or Set Checked Radio Value

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; }

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) { radioObj[i].checked = false; if(radioObj[i].value == newValue.toString()) { radioObj[i].checked = true; } } }

Comments Off on Javascript Get or Set Checked Radio Value

Boy, do I love that "Position is everything" site. Every problem I've been having these days with CSS, the fix can be found there.

Here's today's CSS dilema. Had a simple floated div. Gave it a margin – and for some reason, IE doubled it. The solution is just to add "display: inline;" to the floated div, and all is well.

Ran into this problem today: Had a container div with floated divs inside. However the container div was shrinking up above the bottom of the floated divs inside.

See example here.

Found this solution which basically suggested adding the following so that it wouldn't do that:

.containerdiv:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}

As well as adding a height: 1% (to to the container div)

See fixed example here.

Comments Off on Floated boxes extending outside of container box

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements