[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 4 lt_include( PLOG_CLASS_PATH."class/file/fileupload.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 6 7 define( "FILE_UPLOADS_NOT_ENABLED", -200 ); 8 9 /** 10 * \ingroup File 11 * 12 * Handles file uploads in pLog. 13 * @see FileUpload 14 */ 15 class FileUploads 16 { 17 18 var $_files; 19 var $_blogInfo; 20 21 /** 22 * Creates a new object to handle file uploads. $files is either the 23 * contents of the $_FILES variable (if using PHP >= 4.1.0) or 24 * $HTTP_POST_FILES if earlier version. 25 * 26 * @param files The contents of the array generated by php after a file 27 * has been uploaded. 28 */ 29 function FileUploads( $files ) 30 { 31 32 33 $this->_files = $files; 34 } 35 36 /** 37 * processes only one FileUpload object instead of the whole bunch 38 * 39 * @param uplaod A FileUpload object 40 * @param destinationFolder the destination folder 41 * @return true if successful or false otherwise 42 */ 43 function processFile( $upload, $destinationFolder ) 44 { 45 // first, check if the upload feature is available 46 $config =& Config::getConfig(); 47 48 if( !$config->getValue( "uploads_enabled" )) { 49 return FILE_UPLOADS_NOT_ENABLED; 50 } 51 52 if( $destinationFolder[strlen($destinationFolder)-1] != "/" ) 53 $destinationFolder .= "/"; 54 55 $destFileName = basename( $upload->getTmpName() ); 56 57 if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$destFileName ) ) { 58 $upload->setFolder( $destinationFolder ); 59 $error = 0; 60 } 61 else { 62 $error = 1; 63 } 64 65 $upload->setError( $error ); 66 67 return $error; 68 } 69 70 /** 71 * Goes through the array of files and processes them accordingly. 72 * The result is an array of the appropiate Resource class that has been 73 * created using the ResourceFactory class. 74 * 75 * @return An array of Upload objects that have already been moved to a safer 76 * location. 77 */ 78 function process( $destinationFolder ) 79 { 80 // first, check if the upload feature is available 81 $config =& Config::getConfig(); 82 83 if( !$config->getValue( "uploads_enabled" )) { 84 return FILE_UPLOADS_NOT_ENABLED; 85 } 86 87 // array used to store the files that have already been saved 88 $uploads = Array(); 89 90 if( $destinationFolder[strlen($destinationFolder-1)] != "/" ) 91 $destinationFolder .= "/"; 92 93 foreach( $this->_files as $file ) { 94 $upload = new FileUpload( $file ); 95 96 $destFileName = $upload->getFileName(); 97 98 if( $this->my_move_uploaded_file( $upload->getTmpName(), $destinationFolder.$destFileName ) ) { 99 $upload->setFolder( $destinationFolder ); 100 $upload->setError( 0 ); 101 } 102 else { 103 $upload->setError( 1 ); 104 } 105 array_push( $uploads, $upload ); 106 } 107 108 return $uploads; 109 } 110 111 /** 112 * Implements the a move_uploaded_file that handles multiple partitions. 113 * 114 * @return a boolean that indicates if the file was successfully moved. This will 115 * return false if the file is not an uploaded file. 116 */ 117 function my_move_uploaded_file( $filename, $destination ) 118 { 119 // first check to make sure that this file is an uploaded file 120 if ( !is_uploaded_file($filename) ) 121 { 122 // This file was not an uploaded file, return false 123 return FALSE; 124 } 125 126 return File::rename( $filename, $destination ); 127 } 128 } 129 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |