Source for file upload.php
Documentation is available at upload.php
* FCKeditor - The text editor for internet
* Copyright (C) 2003-2006 Frederico Caldeira Knabben
* Licensed under the terms of the GNU Lesser General Public License:
* http://www.opensource.org/licenses/lgpl-license.php
* For further information visit:
* http://www.fckeditor.net/
* "Support Open Source software. What about a donation today?"
* This is the "File Uploader" for PHP.
* Frederico Caldeira Knabben (fredck@fckeditor.net)
// This is the function that sends the results of the uploading process.
function SendResults( $errorNumber, $fileUrl =
'', $fileName =
'', $customMsg =
'' )
echo
'<script type="text/javascript">' ;
echo
'window.parent.OnUploadCompleted(' .
$errorNumber .
',"' .
str_replace( '"', '\\"', $fileUrl ) .
'","' .
str_replace( '"', '\\"', $fileName ) .
'", "' .
str_replace( '"', '\\"', $customMsg ) .
'") ;' ;
// Check if this uploader has been enabled.
if ( !$Config['Enabled'] )
SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
// Check if the file has been correctly uploaded.
if ( !isset
( $_FILES['NewFile'] ) ||
is_null( $_FILES['NewFile']['tmp_name'] ) ||
$_FILES['NewFile']['name'] ==
'' )
$oFile =
$_FILES['NewFile'] ;
// Get the uploaded file name extension.
$sFileName =
$oFile['name'] ;
// Replace dots in the name with underscores (only one dot can be there... security issue).
if ( $Config['ForceSingleExtension'] )
$sFileName =
preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;
$sOriginalFileName =
$sFileName ;
$sExtension =
substr( $sFileName, ( strrpos($sFileName, '.') +
1 ) ) ;
// The the file type (from the QueryString, by default 'File').
$sType = isset
( $_GET['Type'] ) ?
$_GET['Type'] :
'File' ;
// Check if it is an allowed type.
if ( !in_array( $sType, array('File','Image','Flash','Media') ) )
// Get the allowed and denied extensions arrays.
$arAllowed =
$Config['AllowedExtensions'][$sType] ;
$arDenied =
$Config['DeniedExtensions'][$sType] ;
// Check if it is an allowed extension.
if ( ( count($arAllowed) >
0 &&
!in_array( $sExtension, $arAllowed ) ) ||
( count($arDenied) >
0 &&
in_array( $sExtension, $arDenied ) ) )
// Initializes the counter used to rename the file, if another one with the same name already exists.
// The the target directory.
if ( isset
( $Config['UserFilesAbsolutePath'] ) &&
strlen( $Config['UserFilesAbsolutePath'] ) >
0 )
$sServerDir =
$Config['UserFilesAbsolutePath'] ;
$sServerDir =
GetRootPath() .
$Config["UserFilesPath"] ;
// Compose the file path.
$sFilePath =
$sServerDir .
$sFileName ;
// If a file with that name already exists.
$sFileName =
RemoveExtension( $sOriginalFileName ) .
'(' .
$iCounter .
').' .
$sExtension ;
chmod( $sFilePath, 0777 ) ;
$sFileUrl =
$Config["UserFilesPath"] .
$sFileName ;
Documentation generated on Sun, 09 Mar 2008 23:53:39 -0300 by phpDocumentor 1.4.0