Subversion Repositories Applications.papyrus

Rev

Rev 433 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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