Changeset 42 for trunk/lib/Upload.inc.php
- Timestamp:
- Dec 18, 2005 12:16:03 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Upload.inc.php
r41 r42 1 1 <?php 2 2 /** 3 * Upload.inc.php 3 * Upload.inc.php 4 4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information 5 5 * … … 22 22 23 23 class Upload { 24 24 25 25 // General object parameters. 26 26 var $_params = array( 27 27 28 28 // Which messages do we pass to raiseMsg? 29 29 'display_messages' => UPLOAD_MSG_ALL, 30 30 31 31 // Existing files will be overwritten when there is a name conflict? 32 32 'allow_overwriting' => false, … … 222 222 'ice' => 'x-conference/x-cooltalk', 223 223 ); 224 224 225 225 /** 226 226 * Set (or overwrite existing) parameters by passing an array of new parameters. … … 232 232 { 233 233 if (isset($params) && is_array($params)) { 234 234 235 235 // Enforce valid upload_path parameter. 236 236 if (isset($params['upload_path'])) { … … 249 249 $params['upload_path'] = preg_replace('!/+$!', '', $params['upload_path']); 250 250 } 251 251 252 252 // Merge new parameters with old overriding only those passed. 253 253 $this->_params = array_merge($this->_params, $params); … … 276 276 /** 277 277 * Process uploaded files. Processes files existing within the specified $_FILES['form_name'] array. 278 * It tests for errors, cleans the filename, optionally sets custom file names. It will process 278 * It tests for errors, cleans the filename, optionally sets custom file names. It will process 279 279 * multiple files automatically if the file form element is an array (<input type="file" name="myfiles[]" />). 280 280 * … … 296 296 return false; 297 297 } 298 298 299 299 // Ensure the file form element specified actually exists. 300 300 if (!isset($_FILES[$form_name])) { … … 303 303 return false; 304 304 } 305 305 306 306 if (is_array($_FILES[$form_name]['name'])) { 307 307 $files = $_FILES[$form_name]; … … 318 318 319 319 // To keep this script running even if user tries to stop browser. 320 ignore_user_abort(true); 320 ignore_user_abort(true); 321 321 ini_set('max_execution_time', 300); 322 322 ini_set('max_input_time', 300); … … 332 332 continue; 333 333 } 334 334 335 335 // Determine final file name. 336 336 if ($num == 1) { … … 362 362 // Clean the file name of bad characters. 363 363 $file_name = $this->cleanFileName($file_name); 364 364 365 365 // If the file name has no extension, use the mime-type extension. 366 366 if (!preg_match('/\.[^.]{1,5}$/', $file_name) && function_exists('mime_content_type')) { … … 369 369 } 370 370 } 371 371 372 372 // Set the path and file name. 373 373 $file_path_name = $this->getParam('upload_path') . '/' . $file_name; 374 375 374 375 376 376 // Check The php upload error messages. 377 377 if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) { … … 407 407 continue; 408 408 } 409 409 410 410 // Check to be sure it's an uploaded file. 411 411 if (!is_uploaded_file($files['tmp_name'][$i])) { … … 415 415 continue; 416 416 } 417 417 418 418 // Check to be sure the file is not empty. 419 419 if ($files['size'][$i] < 1) { … … 423 423 continue; 424 424 } 425 425 426 426 // Check to be sure the file has a valid file name extension. 427 427 if (!in_array(strtolower($this->getFilenameExtension($file_name)), $this->getParam('valid_file_extensions'))) { … … 431 431 continue; 432 432 } 433 433 434 434 // Check to be sure the file has a unique file name. 435 435 if (!$this->getParam('allow_overwriting') && $this->exists($file_name)) { … … 439 439 continue; 440 440 } 441 441 442 442 // Move the file to the final place. 443 443 if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) { … … 462 462 } 463 463 } 464 464 465 465 // Return names of files uploaded (or empty array when none processed). 466 466 return $new_file_names; 467 467 } 468 468 469 469 /** 470 470 * Remove file within upload path. … … 481 481 return false; 482 482 } 483 483 484 484 $file_path_name = $this->getParam('upload_path') . '/' . $file_name; 485 485 … … 495 495 } 496 496 } 497 497 498 498 /** 499 499 * Renames a file within the upload path. … … 511 511 return false; 512 512 } 513 513 514 514 $old_file_path_name = $this->getParam('upload_path') . '/' . $old_name; 515 515 $new_file_path_name = $this->getParam('upload_path') . '/' . $new_name; … … 529 529 } 530 530 } 531 531 532 532 /** 533 533 * Tests if a file exists within the current upload_path. … … 544 544 return false; 545 545 } 546 546 547 547 return file_exists($this->getParam('upload_path') . '/' . $file_name); 548 548 } 549 549 550 550 /** 551 * Get filename by glob pattern. Searches a directory for an image that matches the 551 * Get filename by glob pattern. Searches a directory for an image that matches the 552 552 * specified glob pattern and returns the filename of the first file found. 553 553 * … … 620 620 return isset($ext[1]) ? $ext[1] : ''; 621 621 } 622 622 623 623 /** 624 624 * An alias for App::raiseMsg that only sends messages configured by display_messages.
Note: See TracChangeset
for help on using the changeset viewer.