// check image (only throws an error if an image upload was attempted and failed) try { $imageFile = Request::files()->item('fblimage'); switch( $imageFile->getMimeType() ) { case 'image/jpeg': case 'image/pjpeg': case 'image/gif': case 'image/png': // do a bunch of stuff to set the fbl image up for being saved $fblImage = new FBLImage; $fblImage->setImage(new JPEGImage( $imageFile )); $fblImage->setIsMain(true); // this will be the main image try { throw new APIException( "Here is fblImage:", APIException::ERROR_GENERAL, $fblImage ); $fblImage->Save(); } catch( APIException $expecting_this ) { /* this is due to a limitation in PHP being able to retain temp files. * FBLImage currently calls two separate internal save methods. one * wants the FBLParent's ID which isn't available until the FBL is saved * on the last step ... but the JPEG will save just fine. * --------------------------- * This hack is dirtier and nastier than a Vegas streetwalker ... and I know * it. Sorry about that ... */ } $fbl->images()->add($fblImage); break; default: throw new APIException( 'This system will only accept JPEG, GIF, or PNG images, not a "' . $imageFile->getMimeType() . '"' ); } } catch( APIException $e ) { if( $e->getCode() == APIException::ERROR_BOUNDS ) { /* noop cuz there was no uploaded image */ } else { /* bubbly! */ throw $e; } }