Xataface AJAX Upload Module 0.1
jQuery Ajax Upload Widget for Xataface
/Applications/XAMPP/xamppfiles/htdocs/nanofabrication/modules/ajax_upload/actions/ajax_upload_get_thumbnail.php
Go to the documentation of this file.
00001 <?php
00002 class actions_ajax_upload_get_thumbnail {
00003         
00004         const PERMISSION_DENIED = 401;
00005         
00006         function handle($params){
00007         
00008         
00009                 session_write_close();
00010                 header('Connection:close');
00011                 
00012                 $app = Dataface_Application::getInstance();
00013                 $query =& $app->getQuery();
00014                 $mod = Dataface_ModuleTool::getInstance()->loadModule('modules_ajax_upload');
00015                 $baseUrl = $mod->getBaseURL();
00016                 $basePath = dirname(__FILE__).DIRECTORY_SEPARATOR.'..';
00017                 
00018                 
00019                 
00020                 if ( !@$query['--field'] ) throw new Exception("no field specified");
00021                 if ( !@$query['-table'] ) throw new Exception("no table specified");
00022                 
00023                 $recordId = @$query['--recordId'];
00024 
00025                 
00026                 $record = null;
00027                 if ( $recordId ) $record = df_get_record_by_id($recordId);
00028                 
00029                 if ( !$record ) $record = new Dataface_Record($query['-table'], array());
00030                 
00031                 $table = Dataface_Table::loadTable($query['-table']);
00032                 //if ( is_a($record, 'Dataface_Record') and $table->tablename != $record->table()->tablename ){
00033                 //      throw new Exception("Table does not match record.");
00034                 //} else if ( is_a($record, 'Dataface_RelatedRecord') and 
00035                 
00036                 if ( !$table->hasField($query['--field']) ){
00037                         throw new Exception("The specified field does not exist");
00038                 }
00039                 
00040                 if (!$record->checkPermission('view', array('field'=>$query['--field'])) ){
00041                         throw new Exception("You don't have permission to view this field.", self::PERMISSION_DENIED);
00042                 }
00043                 
00044                 $fieldVal = null;
00045                 
00046                 if ( @$query['--tempfileid'] ){
00047                         $fieldVal = $query['--tempfileid'];
00048                 } else {
00049                         $fieldVal = $record->val($query['--field']);
00050                         //echo "Field val: ".$fieldVal.']';
00051                 }
00052                 
00053                 $s = DIRECTORY_SEPARATOR;
00054                 
00055                 $filePath = $basePath.$s.'images'.$s.'file_not_found.png';
00056                 
00057                 $field =& $table->getField($query['--field']);
00058                 $fieldBaseDir = $field['savepath'];
00059                 if ( @$query['--tempfileid'] ){
00060                         $fieldBaseDir .= $s.'uploads';
00061                 }
00062                 
00063                 if ( $fieldVal ){
00064                         
00065                         $testPath = $fieldBaseDir.$s.basename($fieldVal);
00066                         if ( file_exists($testPath) ){
00067                                 $filePath = $testPath;
00068                                 
00069                                 
00070                                 $mimetype = $mod->getMimeType($filePath);
00071                                 if ( !preg_match('/^image\//', $mimetype) ){
00072                                         $filePath = $mod->getThumbnail(null, $filePath);
00073                                 }
00074                         }
00075                 }
00076                 //echo $filePath;exit;
00077                 
00078                 $width = 75;
00079                 if ( @$query['--max_width'] ){
00080                         $width = intval($query['--max_width']);
00081                 }
00082                 $height = 75;
00083                 if ( @$query['--max_height'] ){
00084                         $height = intval($query['--max_height']);
00085                 }
00086                 
00087                 
00088                 require_once 'lib/thumbnail.lib.php';
00089                 Xataface_Thumbnail::outputThumbnail($filePath, $width, $height);
00090                 
00091                 
00092         }
00093 }
 All Data Structures Files Functions Variables