CodeIgniter + qqFileuploader – UPDATED to support IE

I’m using CodeIgniter in a project with the AJAX file uploader qqFileUploader. I wanted my CI controller to handle the upload work for the file uploader instead of a PHP script that lived outside the CI framework. To make this work made a few minor changes to the qq files and I made some changes in CI that force the uploader to always use XHR upload for now and not iframes. Just updated the code to work with iFrames and tested successfully on IE6 and IE8.

Here are the changes:

First, copy the qqfileuploader.php class file to your application/libraries folder. We’ll be loading this as a library in the controller. UPDATE: You’ll want to add a function to the qqFileUploader class in this file. The function will help get the filename for iframe-based uploads. Here is the new function:


public function getFilename() {
$pathinfo = pathinfo($this->file->getName());
$filename = $pathinfo['filename'] . '.' . $pathinfo['extension'];
return $filename;
}

Second, make a minor change to the qqfileuploader.js javascript file so that it will pass the file information to CI using the CI-style URI instead of with query string parameters:

Find the qq.obj2url function. Comment out these two lines:

? encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj())
: encodeURIComponent(nextTemp) + '=' + encodeURIComponent(nextObj)

and in their place put:

? encodeURIComponent(nextObj())
: encodeURIComponent(nextObj)

This just passes the file name of the object to CI and skips the parameter= part. Next find this line:

prefix = (/\?/.test(temp)) ? (/\?$/.test(temp)) ? '' : '&' : '?';

and replace it with:

prefix = (/\?/.test(temp)) ? (/\?$/.test(temp)) ? '' : '/' : '/';

Lastly find:

uristrings.push(encodeURIComponent(temp) + '=' + encodeURIComponent(obj));

And replace it with:

uristrings.push(encodeURIComponent(obj));

Now for the CI controller function:


function uploadFile($filename = null) {
// This forces qqfileuploader to AJAX XHR mode

if (!isset($_FILES['qqfile'])) {
$_GET['qqfile'] = $filename;
}

$this->load->library('qqfileuploader');
// list of valid extensions, ex. array("jpeg", "xml", "bmp")
$allowedExtensions = array('jpg','pdf','png','doc','docx','xls','xlsx','png');
// max file size in bytes
$sizeLimit = 2 * 1024 * 1024;

$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);

$result = $uploader->handleUpload('/tmp/', true);

// Check if the filename is empty which it will be for iframe-based uploads
if (empty($filename)) {
$filename = $uploader->getFilename();
}

if ($result) {
// Get the mime type of the file
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, '/tmp/' . $filename);
$filedata = file_get_contents('/tmp/' . $filename);
// Do something with the file data, like save it to a BLOB or move it somewhere!
}

if ($result) {
// to pass data through iframe you will need to encode all html tags
echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
}
else {
echo htmlspecialchars(json_encode(array("success" => false)), ENT_NOQUOTES);
}

}

Enjoy!

Modulr Case for iPad

We have had our iPad for two months now with no case. We knew we’d need a case from the first day we used it, but always had our sights set on the Modulr case. If you haven’t kept up with Modulr, they make an iPad case that snaps into several other add-on products for various uses.

Modulr Case Image

The Modulr Case itself provides exactly what we wanted in a case, a soft plastic for the main body and a hard cover for the screen when not in use. The headphone jack, dock connector port and the orientation lock all show through the case while the volume controls and power switch must be pressed through the soft plastic cover. The hole for the orientation switch is just small enough to make flipping the switch difficult. The headphone jack hole is also just a bit too small. It works fine for the Apple headphones, but when we plug in our own audio cables the hole is too small to accommodate the wider plugs. I had to cut back the plastic on one of our cables just to fit it into the hole (I didn’t want to consider cutting the Modulr Case).
Aside from these minor deficits we’re very pleased with how the case works in daily use.
Currently, Modulr only sells two add-on products, the Quick Stand and the Slim Mount with more add-ons coming later. We purchased the $99 pre-sale bundle that includes the case and cover, the Quick Stand and the Slim Mount.
The Quick Stand, $19.99 by itself, allows for two modes of operation (unless you get a little creative), both for horizontal, landscape operation. The two modes allow the iPad to sit up high in a picture frame mode or sit lower for operating it on a table or your lap. We definitely use the Quick Stand all around the house. It has turned out to be the most versatile of the two add-ons currently offered. The Quick Stand really doesn’t work in portrait mode very well. Granted, it’s not intended to, but it would be nice for some uses. Most of the time, however, we use the iPad in landscape mode and I’m sure Modulr thought of that when designing the product.

Here is the case in landscape mode using the Quick Stand

We even found that we can mount the iPad in the car using the Quick Stand. Modulr will be coming out with a car mount as an option on their Swing Mount product, but we had great success with the Quick Mount already. We just connected the mount the “wrong” way and clip the mount to a seam in the upholstery of our van. We tried it on a fairly long road trip with great success.

Here we have the Quick Stand mounted to the ceiling of our family van.

The Slim Mount, $29.99 on its own, is a low profile wall mount that allows you to mount the iPad very securely to your wall. The Slim Mount comes with everything you need to mount it to drywall or studs. Our favorite iPad use is in the kitchen both for recipes and for music and photos (using MyFrame) so we mounted it on the wall there. It’s near enough to the stove for occasional reference and central enough for the music and photos. The Slim Mount uses four screws to mount to the wall so it is quite secure when in place. The key with all Modulr mounts is to slide the iPad into the mount until you hear it “pop” into place.
The major deficit of the Slim Mount design is that you have to choose whether you want it mounted vertically or horizontally before you mount and then you’re stuck with that choice. It would have been nice for the mount to allow sliding the iPad in either vertically or horizontally. This would have required the four mounting knobs on the back of the Modulr Case to be in a square instead of a rectangle, but I think the versatility would have been worth it.

Here is the iPad mounted on the kitchen wall using the Slim Mount

The Slim Mount is a nice option, but if your budget is smaller the Quick Stand is so versatile that you may never miss the wall mount option. The current $99 bundle, however, gives you $10 off the items purchased separately so if you have some wall space you want to designate for your iPad spring for the bundle.
Having not tried other iPad cases I can’t compare the Modulr with anything else. After several days of heavy use, however, we’re glad we waited for this setup. The add-on modules, even with the aforementioned drawbacks, make this iPad case stand above anything else we’ve seen advertised.

CodeIgniter PHP Framework

Been spending a lot of time using the PHP MVC framework CodeIgniter, lately. If you’re familiar with Ruby on Rails or Tapestry for Java you’ll love CodeIgniter in the PHP world. I’ve looked at other frameworks many times in an effort to find something with a good ActiveRecord pattern and MVC2 pattern. CI fits the bill perfectly.

Check it out.