Archive for the ‘Web design’ Category

Using PHP to Force Download of Audio Files

Monday, June 7th, 2010


<?php
$f = $_GET['fileName'];
$m = $_GET['mimeType'];
header(“Content-type: $m”);
header(“Content-disposition: attachment; filename=$f”);
readfile(“$f”);
?>
<?php

$f = $_GET['fileName'];

$m = $_GET['mimeType'];

header("Content-type: $m");

header("Content-disposition: attachment; filename=$f");

readfile("$f");

?>

Use:

http://jameswomack.com/deep-thoughts/a/download.php?fileName=Bubble-Calvalry.ogg&mimeType=application/ogg

 

Custom JavaScript Function to Submit Form Data

Tuesday, November 3rd, 2009
function ajaxFunction(formID,resultID)
{
 var xmlhttp;
 if (window.XMLHttpRequest)
 {
 xmlhttp=new XMLHttpRequest();
 }
 else
 {
 // code for IE6, IE5
 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }
 xmlhttp.onreadystatechange=function()
 {
 if(xmlhttp.readyState==4)
 {
 document.getElementById(resultID).innerHTML=xmlhttp.responseText;
 }
 }
 var params = new Array();
 var cleaned = new Array();
 var elems = document.getElementById(formID).elements;
 var j = 0;
 for(var i in elems){
 if(elems[i].name != '' && elems[i].name != undefined && elems[i].name != 'item' && elems[i].name != 'namedItem'){
 cleaned[j] = elems[i];
 j++;
 }
 }
 for(var i in cleaned){
 params += cleaned[i].name+"="+cleaned[i].value+'&';
 }
 xmlhttp.open(document.getElementById(formID).method,document.getElementById(formID).action,true);
 xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 xmlhttp.setRequestHeader("Content-length", params.length);
 xmlhttp.setRequestHeader("Connection", "close");
 xmlhttp.send(params);
}

You pass the function the ID of your form and the ID of the element that you want to hold the response from your server-side script. This script will automatically use the method and action from your opening form tag.

Temecula Website for Tennis Club

Sunday, November 1st, 2009

Temecula Valley Tennis Website

A custom developed PHP/MySQL/CSS/xHTML/JavaScript/Flash website for Temecula Valley Tennis. Including Testimonials, photo gallery, about page, contact form, slideshow and more. This website has a content management system (CMS) that allows the client to edit their own content.

Mini-site for liking/disliking tweets

Sunday, October 11th, 2009

Coded in PHP/MySQL, this website allows anyone to approve or disapprove of twitter tweets without having to login. To view and rate my tweets, you would go to http://jameswomack.com/tweetworthy/james_womack


Let's give tweets what they deserve

Let's give tweets what they deserve



SQL-driven AS3 Menu

Monday, July 27th, 2009

ActionScript Code

Requires the Greensock tweenlite framework, inside the GS folder. Download the zip file using the link below.

as3_xml_sql_menu.fla

import gs.*;

	var xmlLoader:URLLoader = new URLLoader();
	xmlLoader.addEventListener(Event.COMPLETE, showXML);
	xmlLoader.load(new URLRequest("sqlMenu.php"));
	function showXML(e:Event):void {
		XML.ignoreWhitespace = true;
		var menu:XML = new XML(e.target.data);
		var i:Number;
		var j:Number;
		var k:Number;
		for (i=0; i < menu.section.length(); i++) {
			var mc:MovieClip = new MovieClip();
			var mc1:MovieClip = new MovieClip();
			var t:TextField = new TextField();
			t.y = 0;
			t.x = 0;
			t.selectable = true;
			t.width = 200;
			t.height = 80;
			t.htmlText = ""+ menu.section[i].text() +"";
			t.setTextFormat(new TextFormat("Arial", 22));
			t.rotationZ = 0;
			t.autoSize = TextFieldAutoSize.LEFT;
			mc.addChild( t );
			addChild(mc);
			mc.x = 200*i;
			mc.addEventListener(MouseEvent.MOUSE_OVER, showSection);
			mc.addEventListener(MouseEvent.MOUSE_OUT, hideSection);
			for (j=0; j < menu.section[i].subsection.length(); j++) {
				var mc2:MovieClip = new MovieClip();
				var t2:TextField = new TextField();
				t2.y = 0;
				t2.x = 0;
				t2.selectable = true;
				t2.width = 45;
				t2.height = 100;
				t2.htmlText = ""+ menu.section[i].subsection[j].text() +"";		var f2:TextFormat = new TextFormat();
				f2.align = TextFormatAlign.CENTER;
				f2.size = 14;
				f2.font = "Arial";
				t2.setTextFormat(f2);
				t2.rotationZ = 0;
				t2.autoSize = TextFieldAutoSize.CENTER;
				mc2.addChild( t2 );
				mc.addChild(mc2);
				mc2.x = 50*j;
				mc2.y = 30;
				for (k=0; k < menu.section[i].subsection[j].subsubsection.length(); k++) {
					var mc3:MovieClip = new MovieClip();
					var t3:TextField = new TextField();
					t3.y = 0;
					t3.x = 0;
					t3.selectable = true;
					t3.width = 60;
					t3.height = 20;
					t3.htmlText = ""+ menu.section[i].subsection[j].subsubsection[k].text() +"";
					t3.setTextFormat(new TextFormat("Arial", 12));
					t3.rotationZ = 0;
					mc3.addChild( t3 );
					mc2.addChild(mc3);
					mc3.x = 0;
					mc3.y = 20*k+20;
				}//subsection[j].subsubsection.length()
				for (l=1; l < mc2.numChildren; l++) {
					mc2.getChildAt(l).alpha = 0;
					mc2.addEventListener(MouseEvent.MOUSE_OVER, showSubsection);
					mc2.addEventListener(MouseEvent.MOUSE_OUT, hideSubsection);
				}//for (l=1; l < mc2.numChildren; l++)
				}//(j=0; j < menu.section[i].subsection.length(); j++)
				var l:Number;
				for (l=1; l < mc.numChildren; l++) {
					mc.getChildAt(l).alpha = 0;
				}
		}//for (i=0; i < menu.section.length(); i++)
	}//function showXML(e:Event):void
	function showSection(e:MouseEvent) {
		var mc:MovieClip = e.currentTarget as MovieClip;
		var l:Number;
		for (l=1; l < mc.numChildren; l++) {
			TweenLite.to(mc.getChildAt(l), .5, {alpha:1});
		}
	}
	function hideSection(e:MouseEvent) {
		var mc:MovieClip = e.currentTarget as MovieClip;
		var l:Number;
		for (l=1; l < mc.numChildren; l++) {
			TweenLite.to(mc.getChildAt(l), .2, {alpha:0});
		}
	}
	function showSubsection(e:MouseEvent) {
		var mc:MovieClip = e.currentTarget as MovieClip;
		var l:Number;
		for (l=1; l < mc.numChildren; l++) {
			TweenLite.to(mc.getChildAt(l), .5, {alpha:1});
		}
	}
	function hideSubsection(e:MouseEvent) {
		var mc:MovieClip = e.currentTarget as MovieClip;
		var l:Number;
		for (l=1; l < mc.numChildren; l++) {
			TweenLite.to(mc.getChildAt(l), .2, {alpha:0});
		}
	}

PHP Code

Paste into a text editor and save as sqlMenu.php in the same folder as your SWF. PHP files need to be viewed on a webserver to function. This PHP file is grabbing information from your database and formatting it as XML.

In this example, the MySQL database server is localhost, and the username and password are both root. Also, the database name is fashion and has the tables menu, submenu, and subsubmenu. The menu table has two columns: id and section. The submenu table has three columns: id, section and subsection. The subsubmenu table has four columns: id, section, subsection and subsubsection. Filling out these fields appropriately will yield a functioning hierarchical menu in the Flash SWF file. Download the zip below.

sqlMenu

AS3 Function to Encode Spaces into a URL

Wednesday, July 22nd, 2009
function encodespaces(originalstring:String):String
{
var original:Array=originalstring.split(" ");
return(original.join("%20"));
}

Claiming this blog on technorati

Monday, May 25th, 2009

Technorati Profile