Feb 04
Get errors like this?

Warning: dl(): Unable to load dynamic library 'libwebpayclient.so' - libssl.so.4: cannot open shared object file:
Not sure which package to install? Run the code below to find out!
 sudo apt-get install apt-file
 sudo apt-file update
 apt-file search libssl.so

Sep 04

I saw this method used in an old c cook book. Can’t remeber what it’s called, cascading switch anyone??


switch($section)
 {
 case 'year':
 if(empty($select))
 $select = ' * ';
 if(!empty($year))
 $where .= "    AND        `Year Range`    LIKE '%$year%' ";

 case 'submodel':
 if(empty($select))
 $select = ' TRIM(`Year Range`)';
 if(!empty($submodel))
 $where .= "    AND        `Model ID`         LIKE '%$submodel%' ";

 case 'engine':
 if(empty($select))
 $select = ' TRIM(`Model ID`) ';
 if(!empty($engine))
 $where .= "    AND        `Engine Size`     LIKE '%$engine%' ";

 case 'model':
 if(empty($select))
 $select = ' TRIM(`Engine Size`) ';
 if(!empty($model))
 $where .= "    AND     `Model Name`    LIKE '%$model%' ";

 case 'make':
 if(empty($select))
 $select = ' TRIM(`Model Name`) ';
 if(!empty($make))
 $where .= "    AND     `Make`             LIKE '%$make%' ";
 }

Sep 04

This is a simple script to go though a files inside a folder recursively and append the folder name to the file name.

The script is written for a windows system, just replace the \\ to / for unix.


function getDirectory( $path = '.', $level = 0 )
{    $dir_separator = '__';
 $ignore = array( 'cgi-bin', '.', '..','default.asp','index.php','PUT SELF IN THERE' );
 // Directories to ignore when listing output. Many hosts
 // will deny PHP access to the cgi-bin.

 $dh = @opendir( $path );
 // Open the directory to the handle $dh

 while( false !== ( $file = readdir( $dh ) ) ){
 // Loop through the directory

 if( !in_array( $file, $ignore ) && !strstr($file, $dir_separator))
 {    // Check that this file is not to be ignored
 //AND ALSO CHECK IF WE HAVENT ALRADY DONE THIS

 $spaces = str_repeat( ' ', ( $level * 4 ) );
 // Just to add spacing to the list, to better
 // show the directory tree.

 if( is_dir( "$path\\$file" ) )
 {    // Its a directory, so we need to keep reading down...

 //echo "<strong>$spaces $file</strong><br />";
 getDirectory( "$path\\$file", ($level+1) );
 // Re-call this same function but on a new directory.
 // this is what makes function recursive.
 } else {
 $rooot_path = 'C:\\xampp\\htdocs\\Documents';
 $old_filename = $rooot_path.substr("$path\\$file",1);
 $new_filename = substr($path,2);
 $new_filename = $rooot_path.substr('.\\'.$new_filename.'\\'.str_replace('\\',$separator,$new_filename).$separator.$file,1);
 echo "$old_filename -> $new_filename <br />";
 rename($old_filename,$new_filename);
 }
 }

 }
 closedir( $dh );
 // Close the directory handle
}

//run the function
getDirectory( "." );

Aug 24
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://cultivatewebdesign.com.au%{REQUEST_URI}

Aug 04
Cultivate Firefox persona

Cultivate Firefox persona

Check out the:

Firefox 3 Persona by Cultivate web design Melbourne

They are easy to create and offers great viral marketing value for your business.

Aug 04

While iframes are not good to use normaly, I use it to mix different server side languages. (eg: pulling through perl/ASP scripts to display on a php page). Please only use this for non indexed (admin/managemt/report) pages because iframes are no good for SEO.

Javascript for the parent page,

//this uses mootools. This code should be placed inside domready or load event of the window
$('my-iframe').addEvent('load',function()
{	innerDoc = ($('my-iframe').contentDocument) ? $('my-iframe').contentDocument : $('my-iframe').contentWindow.document;
	objToResize = ($('my-iframe').style) ? $('my-iframe').style : $('my-iframe');
	objToResize.height = (innerDoc.body.scrollHeight + 50) + 'px';
	objToResize.width = (innerDoc.body.scrollWidth + 20) + 'px';
	window.scrollTo(0, 0);//optional code to scroll the parent window back to top
});

And the iframe should look like this,

<iframe id="my-iframe" src="my_page_to_iframe.php" frameborder="0" scrolling="auto" ></iframe>

Thats it! If the sites are on two domains, take a look at this post to get around that.

Aug 04

There are a few ways to get around the browser limitations if we want to run javascript thats on an iframe on our site. One method is toadd a iframe the 2nd site referencing the 1st side. So you end up with two iframes.

Another way is by setting up a proxy forward using a rewrite rule. This way you can access a page on your side, say http://cultivatewebdesign.com.au/google.html and actaully access google.com. Heres how,

RewriteRule   ^/google.html                                      http://google.com     [P]

Aug 03

Unfortunatly we only lhave a few ways to upload files without reloading the whole page. You can do this by using an iframe, flash or through a java applet. Since applets support drag and drop, we can use it to create a drag and drop file uploader.

This is the html to hold the java applet. We chuck in a text field so we can pass additional information with the applet’s file post.

    <input id="meta-text" />
    <button onclick="javascript:document.applets.uploadApplet.setMetadata(document.getElementById('meta-text').value);">Set metadata</button>
    <br />
    <applet type="application/x-java-applet" name="uploadApplet" id="uploadApplet" code="dndapplet/applet/DNDApplet" archive="signed_dndapplet.jar" mayscript="true" scriptable="true">
        <param name="uploadPath"                      value="uploader.php">
        <param name="funcNameHandleCurrentUpload"     value="handleCurrentUpload">
    </applet>

When a file is draged and dropped into the applet, it submits the file to the location passed through the uploadPath param. The upload works the same way as any FILE/POST form submit. So we write some PHP to handle it and return how the upload went.

$uploadPath = "./uploads";
$maxfilesize = 30000; //kByte
$tmp_name  = $_FILES['uploadfile']['tmp_name'];
$file_name = $_FILES['uploadfile']['name'];
$tgt_path  = "$uploadPath/$file_name";
$field_name = 'uploadfile';

if ($_FILES['uploadfile']['size'] > $maxfilesize*1024)
   die ("File exceeds maximum filesize: $maxfilesize kByte.");

if ( ! is_writable( $uploadPath) )
	die ("Upload path is not writeable.");

if ( ! move_uploaded_file( $tmp_name, $tgt_path ) )
  die ("Problem during upload.");

echo "$file_name Upload successful. Metadata: " . $_POST['metadata'];

Finally, we have to go back to the html page and write some javascipt to handle the value returned by the applet.

function javascript_callback (return_str)
{	alert(return_str);
}

Now we are all done. You can download the demo and the source code live demo link . If you want to change the appearance of the applet, you can edit the code .

Here’s the live demo link and the full source code

Jul 31
LOAD DATA LOCAL INFILE '/home/chris/members.csv' INTO TABLE members_new FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (lastname, firstname, dob);

Jul 28

OffsetHeight property returns the elements real width including borders, margin and padding.
This is a IE introduced property not in w3c but now implemented in almost all browsers. Maybe we should try using mootools new get calculated width/height?

We combined this with phatfusions validate to only validate visible fields on forms.

Element.implement(
{	isHidden: function()
{	var w = this.offsetWidth, h = this.offsetHeight,
force = (this.tagName === 'TR');
return (w===0 &amp;&amp; h===0 &amp;&amp; !force) ? true : (w!==0 &amp;&amp; h!==0 &amp;&amp; !force) ? false : this.getStyle('display') === 'none';
},

isVisible: function()
{	return !this.isHidden();
}
});