Changeset 648 for branches/1.1dev/lib
- Timestamp:
- Oct 25, 2018 12:35:37 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.1dev/lib/Upload.inc.php
r391 r648 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 */ … … 16 16 17 17 class Upload { 18 18 19 19 // Display error messages to the user? 20 20 var $display_messages = true; 21 21 22 22 // Existing files with the same name will be overwritten? 23 23 var $allow_overwriting = false; … … 28 28 // Array of files with errors. 29 29 var $errors = array(); 30 30 31 31 // Array of acceptable file extensions (lowercase). 32 32 var $valid_file_extensions = array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'txt', 'text', 'html', 'htm'); 33 34 // The uploaded files will be owned by user 'apache'. Set world-read/write 33 34 // The uploaded files will be owned by user 'apache'. Set world-read/write 35 35 // if the website admin needs to read/delete these files. 36 36 var $dest_file_perms = 0600; 37 37 38 38 // Array of file extensions and corresponding mime-types. 39 39 var $mime_extension_map = array( … … 221 221 { 222 222 $path = realpath($path); 223 223 224 224 if (!is_dir($path)) { 225 225 logMsg(sprintf('Upload directory invalid: %s', $path), LOG_ERR, __FILE__, __LINE__); … … 228 228 logMsg(sprintf('Upload directory not writable: %s', $path), LOG_ERR, __FILE__, __LINE__); 229 229 } 230 230 231 231 // Set the default upload path, stripping any extra slashes if needed. 232 232 $this->upload_directory_path = preg_replace('!/+$!', '', $path); … … 246 246 return false; 247 247 } 248 248 249 249 if (!isset($_FILES[$form_name])) { 250 250 logMsg(sprintf(_("Form element %s not posted."), $form_name), LOG_ERR, __FILE__, __LINE__); … … 254 254 return false; 255 255 } 256 256 257 257 if (is_array($_FILES[$form_name]['name'])) { 258 258 $files = $_FILES[$form_name]; … … 269 269 270 270 // To keep this script running even if user tries to stop browser. 271 ignore_user_abort(true); 272 if (!ini_get('safe_mode')) { 273 set_time_limit(300); 271 ignore_user_abort(true); 272 if (!ini_get('safe_mode')) { 273 set_time_limit(300); 274 274 } 275 275 … … 284 284 continue; 285 285 } 286 286 287 287 // Check The php upload error messages. 288 288 if (UPLOAD_ERR_INI_SIZE === $files['error'][$i]) { … … 326 326 continue; 327 327 } 328 328 329 329 // Check to be sure it's an uploaded file. 330 330 if (!is_uploaded_file($files['tmp_name'][$i])) { … … 336 336 continue; 337 337 } 338 338 339 339 // Check to be sure the file is not empty. 340 340 if ($files['size'][$i] < 1) { … … 346 346 continue; 347 347 } 348 348 349 349 // Check to be sure the file has a valid file extension. 350 350 if (!in_array(strtolower($this->getFilenameExtension($files['name'][$i])), $this->valid_file_extensions)) { … … 356 356 continue; 357 357 } 358 358 359 359 // Check to be sure the file has a unique file name. 360 360 if (!$this->allow_overwriting && $this->exists($files['name'][$i])) { … … 366 366 continue; 367 367 } 368 368 369 369 // Determine file name. 370 370 if ($num == 1) { … … 413 413 // Clean the file name of bad characters. 414 414 $file_name = $this->cleanFileName($file_name); 415 415 416 416 // If the file name has no extension, use the mime-type extension. 417 417 if (!preg_match('/\.[^.]{1,5}$/', $file_name) && function_exists('mime_content_type')) { … … 420 420 } 421 421 } 422 422 423 423 // Set the path and file name. 424 424 $file_path_name = $this->upload_directory_path . '/' . $file_name; 425 425 426 426 // Move the file to the final place. 427 427 if (move_uploaded_file($files['tmp_name'][$i], $file_path_name)) { … … 456 456 return (sizeof($new_file_names) > 0) ? $new_file_names : false; 457 457 } 458 458 459 459 /** 460 460 * … … 467 467 return false; 468 468 } 469 469 470 470 $file_path_name = $this->upload_directory_path . '/' . $file_name; 471 471 … … 483 483 } 484 484 } 485 485 486 486 /** 487 487 * … … 494 494 return false; 495 495 } 496 496 497 497 $old_file_path_name = $this->upload_directory_path . '/' . $old_name; 498 498 $new_file_path_name = $this->upload_directory_path . '/' . $new_name; … … 513 513 } 514 514 } 515 515 516 516 /** 517 517 * … … 524 524 return false; 525 525 } 526 526 527 527 return file_exists($this->upload_directory_path . '/' . $file_name); 528 528 }
Note: See TracChangeset
for help on using the changeset viewer.