ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

file_input_controller.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD license. All other third side source code (like tinyMCE) is distributed under
6 * it's own license wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
16 //TODO: create default page for file uploads with name 'upload_file.html' with public permit
17
28 class file_input_controller_1_0_0{
29
40 var $UploadedFile = false;
41
52 var $FileInputAlgorithms = false;
53 var $Security = false;
54
69 function __construct()
70 {
71 try
72 {
73 $this->FileInputAlgorithms = get_package( 'file_input::file_input_algorithms' , 'last' , __FILE__ );
74 $this->Security = get_package( 'security' , 'last' , __FILE__ );
75 }
76 catch( Exception $e )
77 {
78 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
79 }
80 }
81
112 function save_uploaded_file( $SavePath , $FileName , $OriginalFileName )
113 {
114 try
115 {
116 $FileInputAccess = get_package( 'file_input::file_input_access' , 'last' , __FILE__ );
117
118 $Record = array( 'file_path' => $SavePath.$FileName , 'original_file_name' => $OriginalFileName );
119 $id = $FileInputAccess->create( $Record );
120
121 $EventManager = get_package( 'event_manager' , 'last' , __FILE__ );
122 $EventManager->trigger_event( 'on_load_file' , array( 'id' => $id ) );
123
124 $Record[ 'id' ] = $id;
125 $FileInputAlgorithms = get_package( 'file_input::file_input_algorithms' , 'last' , __FILE__ );
126 $this->UploadedFile = $Record;
127
128 return( $id );
129 }
130 catch( Exception $e )
131 {
132 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
133 }
134 }
135
162 function display_file_info( $SavePath , $FileId , $OriginalFileName )
163 {
164 try
165 {
166 $ServerData = new stdClass;
167 set_field( $ServerData , 'href' , $SavePath );
168 set_field( $ServerData , 'id' , $FileId );
169 set_field( $ServerData , 'original_file_name' , $OriginalFileName );
170
171 $JSON = get_package( 'json' , 'last' , __FILE__ );
172 print_r( $JSON->encode( $ServerData ) );
173 }
174 catch( Exception $e )
175 {
176 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
177 }
178 }
179
202 function handle_request( &$Options )
203 {
204 try
205 {
206 global $extension_whitelist;
207 $extension_whitelist = $this->FileInputAlgorithms->get_extensions(
208 $Options->get_setting( 'file_types' , 'default' )
209 );
210
211 $PackagePath = _get_package_relative_path_ex( 'file_input::file_input_controller' , '1.0.0' );
212 $DirectoryPath = $PackagePath.'/data/'.date( 'Ymd' );
213 @mkdir_ex( $DirectoryPath );
214
215 global $save_path;
216 $save_path = $DirectoryPath.'/';
217 global $file_name;
218 global $original_file_name;
219 define( 'NO_DIRECT_CALL' , 1 );
220 require_once( $PackagePath.'/include/php/upload.php' );
221
222 return( array( $save_path , $file_name , $original_file_name ) );
223 }
224 catch( Exception $e )
225 {
226 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
227 }
228 }
229
248 function upload_file( &$Options )
249 {
250 try
251 {
252 list( $save_path , $file_name , $original_file_name ) = $this->handle_request( $Options );
253
254 $id = $this->save_uploaded_file( $save_path , $file_name , $original_file_name );
255
256 $VarName = $this->Security->get_gp( 'page_name' , 'command' ).'_file';
257 if( $Options->get_setting( 'var_name' , false ) !== false )
258 {
259 $VarName = $Options->get_setting( 'var_name' );
260 }
261 /* saving info in the session */
262 $this->Security->set_s( $VarName , $id );
263
264 $this->display_file_info( $save_path."$file_name" , $id , $original_file_name );
265 }
266 catch( Exception $e )
267 {
268 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
269 }
270 }
271
290 function controller( $Options )
291 {
292 try
293 {
294 $UploadFile = $Options->get_setting( 'upload_file' , false );
295 $NotDirectControllerCall = $this->Security->get_s( 'direct_controller' , 'integer' , 0 ) == 0;
296
297 if( $UploadFile && $NotDirectControllerCall && count( $_FILES ) )
298 {
299 $this->upload_file( $Options );
300 }
301 }
302 catch( Exception $e )
303 {
304 $a = func_get_args();_throw_exception_object( __METHOD__ , $a , $e );
305 }
306 }
307 }
308
309 ?>