[ Index ] |
|
Code source de CMS made simple 1.0.5 |
1 <?php 2 /* 3 * FCKeditor - The text editor for Internet - http://www.fckeditor.net 4 * Copyright (C) 2003-2007 Frederico Caldeira Knabben 5 * 6 * == BEGIN LICENSE == 7 * 8 * Licensed under the terms of any of the following licenses at your 9 * choice: 10 * 11 * - GNU General Public License Version 2 or later (the "GPL") 12 * http://www.gnu.org/licenses/gpl.html 13 * 14 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") 15 * http://www.gnu.org/licenses/lgpl.html 16 * 17 * - Mozilla Public License Version 1.1 or later (the "MPL") 18 * http://www.mozilla.org/MPL/MPL-1.1.html 19 * 20 * == END LICENSE == 21 * 22 * This is the "File Uploader" for PHP. 23 */ 24 25 require_once(dirname(dirname(dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))))) . '/include.php'); 26 check_login(); 27 28 require ('config.php') ; 29 require ('util.php') ; 30 31 // This is the function that sends the results of the uploading process. 32 function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' ) 33 { 34 echo '<script type="text/javascript">' ; 35 echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ; 36 echo '</script>' ; 37 exit ; 38 } 39 40 // Check if this uploader has been enabled. 41 if ( !$Config['Enabled'] ) 42 SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ; 43 44 // Check if the file has been correctly uploaded. 45 if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' ) 46 SendResults( '202' ) ; 47 48 // Get the posted file. 49 $oFile = $_FILES['NewFile'] ; 50 51 // Get the uploaded file name extension. 52 $sFileName = $oFile['name'] ; 53 54 // Replace dots in the name with underscores (only one dot can be there... security issue). 55 if ( $Config['ForceSingleExtension'] ) 56 $sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ; 57 58 $sOriginalFileName = $sFileName ; 59 60 // Get the extension. 61 $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ; 62 $sExtension = strtolower( $sExtension ) ; 63 64 // The the file type (from the QueryString, by default 'File'). 65 $sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ; 66 67 // Check if it is an allowed type. 68 if ( !in_array( $sType, array('File','Image','Flash','Media') ) ) 69 SendResults( 1, '', '', 'Invalid type specified' ) ; 70 71 // Get the allowed and denied extensions arrays. 72 $arAllowed = $Config['AllowedExtensions'][$sType] ; 73 $arDenied = $Config['DeniedExtensions'][$sType] ; 74 75 // Check if it is an allowed extension. 76 if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) ) 77 SendResults( '202' ) ; 78 79 $sErrorNumber = '0' ; 80 $sFileUrl = '' ; 81 82 // Initializes the counter used to rename the file, if another one with the same name already exists. 83 $iCounter = 0 ; 84 85 // Get the target directory. 86 if ( isset( $Config['UserFilesAbsolutePath'] ) && strlen( $Config['UserFilesAbsolutePath'] ) > 0 ) 87 $sServerDir = $Config['UserFilesAbsolutePath'] ; 88 else 89 $sServerDir = GetRootPath() . $Config["UserFilesPath"] ; 90 91 if ( $Config['UseFileType'] ) 92 $sServerDir .= $sType . '/' ; 93 94 if ($sType == 'Image') 95 $sServerDir = $config['image_uploads_path'] . '/'; 96 97 while ( true ) 98 { 99 // Compose the file path. 100 $sFilePath = $sServerDir . $sFileName ; 101 102 // If a file with that name already exists. 103 if ( is_file( $sFilePath ) ) 104 { 105 $iCounter++ ; 106 $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ; 107 $sErrorNumber = '201' ; 108 } 109 else 110 { 111 move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; 112 113 if ( is_file( $sFilePath ) ) 114 { 115 $oldumask = umask(0) ; 116 chmod( $sFilePath, 0777 ) ; 117 umask( $oldumask ) ; 118 } 119 120 if ($sType == 'Image') 121 $sFileUrl = $config['image_uploads_url'] . '/' . $sFileName; 122 elseif ( $Config['UseFileType'] ) 123 $sFileUrl = $Config["UserFilesPath"] . $sType . '/' . $sFileName ; 124 else 125 $sFileUrl = $Config["UserFilesPath"] . $sFileName ; 126 127 break ; 128 } 129 } 130 131 SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ; 132 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Tue Apr 3 18:50:37 2007 | par Balluche grâce à PHPXref 0.7 |