/**
  * show upload form
  *
  * @return void
  * @author Andy Bennett
  */
 public static function upload_form()
 {
     Assets::instance()->add_css('/cache/css/swfupload/default');
     Assets::instance()->add_javascript('/cache/js/swfupload/swfupload');
     Assets::instance()->add_javascript('/cache/js/swfupload/swfupload.swfobject');
     Assets::instance()->add_javascript('/cache/js/swfupload/swfupload.queue');
     Assets::instance()->add_javascript('/cache/js/swfupload/fileprogress');
     Assets::instance()->add_javascript('/cache/js/swfupload/handlers');
     $s = URI::instance()->segment(1);
     Session::instance();
     $gal = Input::instance()->get('gallery_id');
     if (!is_numeric($gal)) {
         $gal = 0;
     }
     $u = isset($_GET['ajax']) ? '?ajax=true' : '';
     $config = array();
     $config['flash_url'] = url::site() . "cache/swf/swfupload/swfupload.swf";
     $config['post_upload_url'] = url::site() . $s . "/post_upload/" . $gal . $u;
     $config['upload_url'] = url::site() . $s . "/process_upload" . $u;
     $config['session_id'] = session_id();
     $config['postname'] = gallery_helper::get_upload_config()->upload_name;
     $config['filetypes'] = '*.' . implode(';*.', gallery_helper::get_upload_config()->extension_whitelist);
     $config['cat_id'] = $gal;
     Display::instance()->add_head_content(View::factory('upload_head_js', $config)->render());
     Display::instance()->display(View::factory('pages/' . $s . '_upload', array('gal' => $gal)));
 }
 /**
  * generic galleries function
  *
  * @return void
  * @author Andy Bennett
  */
 function index()
 {
     $gid = gallery_helper::get_gallery_number();
     $data = $this->get_list($gid);
     $data['gallery'] = $this->uri->segment(1);
     $data['view'] = $this->setup['view'];
     $data['gal'] = $gid;
     Event::run('show_gallery_list', $data);
 }
<div id="upload-content">
	<h2>Upload new photographs</h2>
	<form id="form1" action="/gallery/process_upload" method="post" enctype="multipart/form-data">
		<p>Select gallery: <select name="cat_id" id="cat_id">
		  <?php 
$categories = gallery_helper::get_galleries();
foreach ($categories as $c) {
    ?>
		  	<option value="<?php 
    echo $c->id;
    ?>
" <?php 
    echo $gal == $c->id ? 'selected="true"' : "";
    ?>
><?php 
    echo $c->title;
    ?>
</option>
		  <?php 
}
?>
		</select></p>

			<fieldset class="flash" id="fsUploadProgress">
			<legend>Upload Queue</legend>
			</fieldset>
		<div id="divStatus">0 Files Uploaded</div>
			<div>
				<input type="button" value="Choose files (Max 100 MB)" onclick="swfu.selectFiles()" style="font-size: 8pt;" />
				<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="font-size: 8pt;" />
				<input type="button" value="Upload files" onclick="swfu.startUpload();" style="font-size: 8pt;" />
 /**
  * Process upload function
  *
  * @return void
  * @author Andy Bennett
  */
 function process_upload()
 {
     try {
         $conf = gallery_helper::get_upload_config();
         // Settings
         $upload_name = $conf->upload_name;
         // Kohana::log('error', Kohana::debug($_FILES));
         // Validate the upload
         if (!isset($_FILES[$upload_name])) {
             throw new Exception("No upload found in \$_FILES for " . $upload_name);
         } elseif (isset($_FILES[$upload_name]["error"]) and $_FILES[$upload_name]["error"] != 0) {
             throw new Exception($uploadErrors[$_FILES[$upload_name]["error"]]);
         } elseif (!isset($_FILES[$upload_name]["tmp_name"]) or !@is_uploaded_file($_FILES[$upload_name]["tmp_name"])) {
             throw new Exception("Upload failed is_uploaded_file test.");
         } elseif (!isset($_FILES[$upload_name]['name'])) {
             throw new Exception("File has no name.");
         }
         $file_data = $_FILES[$upload_name];
         $file = $upload_name;
         $gallery_item = ORM::factory('gallery');
         $gallery_item->galleries_id = $_POST['gallery'];
         $gallery_item->title = $file_data['name'];
         $gallery_item->status = 1;
         $gallery_item->navorder = 1;
         $gallery_item->date_added = date('Y-m-d H:i:s');
         $gallery_item->date_modified = date('Y-m-d H:i:s');
         $gallery_item->save();
         Event::run('steamcore.crud_upload', $gallery_item);
         // Save the upload details - eventually this will be gallery item IDs
         if (!Session::instance()->get('image_id')) {
             Session::instance()->set('image_id', array());
         }
         $arr = Session::instance()->get('image_id');
         $arr[] = $gallery_item->id;
         Session::instance()->set('image_id', $arr);
         // Return output to the browser (only supported by SWFUpload for Flash Player 9)
         echo "File Received ";
         // Needed because we exit the script
         exit(0);
     } catch (Exception $e) {
         Kohana::log('error', 'upload error: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
         header("HTTP/1.1 500 Internal Server Error");
         echo $message;
     }
 }