431 |
ddelon |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* FCKeditor - The text editor for internet
|
|
|
4 |
* Copyright (C) 2003-2005 Frederico Caldeira Knabben
|
|
|
5 |
*
|
|
|
6 |
* Licensed under the terms of the GNU Lesser General Public License:
|
|
|
7 |
* http://www.opensource.org/licenses/lgpl-license.php
|
|
|
8 |
*
|
|
|
9 |
* For further information visit:
|
|
|
10 |
* http://www.fckeditor.net/
|
|
|
11 |
*
|
|
|
12 |
* File Name: upload.php
|
|
|
13 |
* This is the "File Uploader" for PHP.
|
|
|
14 |
*
|
|
|
15 |
* File Authors:
|
|
|
16 |
* Frederico Caldeira Knabben (fredck@fckeditor.net)
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
require('config.php') ;
|
|
|
20 |
require('util.php') ;
|
|
|
21 |
|
|
|
22 |
// This is the function that sends the results of the uploading process.
|
|
|
23 |
function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
|
|
|
24 |
{
|
|
|
25 |
echo '<script type="text/javascript">' ;
|
|
|
26 |
echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
|
|
|
27 |
echo '</script>' ;
|
|
|
28 |
exit ;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
// Check if this uploader has been enabled.
|
|
|
32 |
if ( !$Config['Enabled'] )
|
|
|
33 |
SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
|
|
|
34 |
|
|
|
35 |
// Check if the file has been correctly uploaded.
|
|
|
36 |
if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
|
|
|
37 |
SendResults( '202' ) ;
|
|
|
38 |
|
|
|
39 |
// Get the posted file.
|
|
|
40 |
$oFile = $_FILES['NewFile'] ;
|
|
|
41 |
|
|
|
42 |
// Get the uploaded file name and extension.
|
|
|
43 |
$sFileName = $oFile['name'] ;
|
|
|
44 |
$sOriginalFileName = $sFileName ;
|
|
|
45 |
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
|
|
|
46 |
$sExtension = strtolower( $sExtension ) ;
|
|
|
47 |
|
|
|
48 |
// The the file type (from the QueryString, by default 'File').
|
|
|
49 |
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
|
|
|
50 |
|
|
|
51 |
// Get the allowed and denied extensions arrays.
|
|
|
52 |
$arAllowed = $Config['AllowedExtensions'][$sType] ;
|
|
|
53 |
$arDenied = $Config['DeniedExtensions'][$sType] ;
|
|
|
54 |
|
|
|
55 |
// Check if it is an allowed extension.
|
|
|
56 |
if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) )
|
|
|
57 |
SendResults( '202' ) ;
|
|
|
58 |
|
|
|
59 |
$sErrorNumber = '0' ;
|
|
|
60 |
$sFileUrl = '' ;
|
|
|
61 |
|
|
|
62 |
// Initializes the counter used to rename the file, if another one with the same name already exists.
|
|
|
63 |
$iCounter = 0 ;
|
|
|
64 |
|
|
|
65 |
// The the target directory.
|
436 |
ddelon |
66 |
//$sServerDir = GetRootPath() . $Config["UserFilesPath"] ;
|
|
|
67 |
$sServerDir = $Config['BaseDir'].$Config["UserFilesPath"].'/';
|
431 |
ddelon |
68 |
|
|
|
69 |
while ( true )
|
|
|
70 |
{
|
|
|
71 |
// Compose the file path.
|
|
|
72 |
$sFilePath = $sServerDir . $sFileName ;
|
|
|
73 |
|
|
|
74 |
// If a file with that name already exists.
|
|
|
75 |
if ( is_file( $sFilePath ) )
|
|
|
76 |
{
|
|
|
77 |
$iCounter++ ;
|
|
|
78 |
$sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
|
|
|
79 |
$sErrorNumber = '201' ;
|
|
|
80 |
}
|
|
|
81 |
else
|
|
|
82 |
{
|
|
|
83 |
move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
|
|
|
84 |
|
|
|
85 |
if ( is_file( $sFilePath ) )
|
|
|
86 |
{
|
|
|
87 |
$oldumask = umask(0) ;
|
|
|
88 |
chmod( $sFilePath, 0777 ) ;
|
|
|
89 |
umask( $oldumask ) ;
|
|
|
90 |
}
|
|
|
91 |
|
436 |
ddelon |
92 |
$sFileUrl = $Config["UrlPrefix"].$Config["UserFilesPath"]."/". $sFileName ;
|
|
|
93 |
|
431 |
ddelon |
94 |
break ;
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
|
|
|
99 |
?>
|