3
* FCKeditor - The text editor for internet
4
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
6
* Licensed under the terms of the GNU Lesser General Public License:
7
* http://www.opensource.org/licenses/lgpl-license.php
9
* For further information visit:
10
* http://www.fckeditor.net/
12
* "Support Open Source software. What about a donation today?"
14
* File Name: upload.php
15
* This is the "File Uploader" for PHP.
18
* Frederico Caldeira Knabben (fredck@fckeditor.net)
21
require('config.php') ;
24
// This is the function that sends the results of the uploading process.
25
function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
27
echo '<script type="text/javascript">' ;
28
echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
33
// Check if this uploader has been enabled.
34
if ( !$Config['Enabled'] )
35
SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
37
// Check if the file has been correctly uploaded.
38
if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
39
SendResults( '202' ) ;
41
// Get the posted file.
42
$oFile = $_FILES['NewFile'] ;
44
// Get the uploaded file name and extension.
45
$sFileName = $oFile['name'] ;
46
$sOriginalFileName = $sFileName ;
47
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
48
$sExtension = strtolower( $sExtension ) ;
50
// The the file type (from the QueryString, by default 'File').
51
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
53
// Get the allowed and denied extensions arrays.
54
$arAllowed = $Config['AllowedExtensions'][$sType] ;
55
$arDenied = $Config['DeniedExtensions'][$sType] ;
57
// Check if it is an allowed extension.
58
if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) )
59
SendResults( '202' ) ;
64
// Initializes the counter used to rename the file, if another one with the same name already exists.
67
// The the target directory.
68
$sServerDir = GetRootPath() . $Config["UserFilesPath"] ;
72
// Compose the file path.
73
$sFilePath = $sServerDir . $sFileName ;
75
// If a file with that name already exists.
76
if ( is_file( $sFilePath ) )
79
$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
80
$sErrorNumber = '201' ;
84
move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
86
if ( is_file( $sFilePath ) )
88
$oldumask = umask(0) ;
89
chmod( $sFilePath, 0777 ) ;
93
$sFileUrl = $Config["UserFilesPath"] . $sFileName ;
99
SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
b'\\ No newline at end of file'