Xataface AJAX Upload Module 0.1
jQuery Ajax Upload Widget for Xataface
/Applications/XAMPP/xamppfiles/htdocs/nanofabrication/modules/ajax_upload/actions/ajax_upload_get_temp_file_details.php
Go to the documentation of this file.
00001 <?php
00002 class actions_ajax_upload_get_temp_file_details {
00003         function handle($params){
00004                 session_write_close();
00005                 header('Connection:close');
00006         
00007                 $app = Dataface_Application::getInstance();
00008                 $query = $app->getQuery();
00009                 
00010                 //if ( !@$query['--fileid'] ){
00011                 //      throw new Exception("No file id specified");
00012                 //}
00013                 
00014                 if ( !@$query['--field'] ){
00015                         throw new Exception("No field specified");
00016                 }
00017                 
00018                 if ( !@$query['-table'] ){
00019                         throw new Exception("No table specified");
00020                 }
00021                 
00022                 $table = Dataface_Table::loadTable($query['-table']);
00023                 $field =& $table->getField($query['--field']);
00024                 
00025                 $path = $field['savepath'];
00026                 if ( @$query['--fileid'] ){
00027                         $uploadsDir = $path.DIRECTORY_SEPARATOR.'uploads';
00028                         $filePath = $uploadsDir.DIRECTORY_SEPARATOR.basename($query['--fileid']);
00029                         
00030                         if ( !file_exists($filePath) ){
00031                                 throw new Exception("File does not exist: ".$filePath);
00032                         }
00033                         $infoPath = $filePath.'.info';
00034                         if ( !file_exists($infoPath) ){
00035                                 throw new Exception("Info file does not exist");
00036                         }
00037                         
00038                         $serializedData = trim(file_get_contents($infoPath));
00039                         if ( !$serializedData ){
00040                                 throw new Exception("No info found in info file.");
00041                         }
00042                         $data = unserialize($serializedData);
00043                 } else {
00044                         $recordId = $query['--recordId'];
00045                         if ( $recordId ) $record = df_get_record_by_id($recordId);
00046                         else $record = new Dataface_Record($query['-table'], array());
00047                         
00048                         $val = $record->val($query['--field']);
00049                         if ( !$record->checkPermission('view', array('field'=>$query['--field']))){
00050                                 throw new Exception("Permission denied.  You don't have permission to view this field.");
00051                                 
00052                         }
00053                         if ( !$val ){
00054                                 throw new Exception("No value found for this field");
00055                         }
00056                         $filePath = $path.DIRECTORY_SEPARATOR.basename($val);
00057                         
00058                         $data = array(
00059                                 'name'=> $val,
00060                                 'type'=>Dataface_ModuleTool::getInstance()->loadModule('modules_ajax_upload')->getMimeType($filePath),
00061                                 'size'=>filesize($filePath),
00062                                 'url' => $record->display($query['--field'])
00063                         );
00064                 }
00065                 
00066                 
00067                 $out = array(
00068                         'name' => $data['name'],
00069                         'type' => $data['type'],
00070                         'size' => $data['size']
00071                 );
00072                 if ( @$data['url'] ) $out['url'] = $data['url'];
00073                 
00074                 header('Content-type: text/json; charset="'.$app->_conf['oe'].'"');
00075                 echo json_encode($out);
00076                 
00077                 
00078         }
00079 }
 All Data Structures Files Functions Variables