~ubuntu-branches/ubuntu/natty/moin/natty-updates

« back to all changes in this revision

Viewing changes to wiki/htdocs/applets/FCKeditor/editor/filemanager/upload/php/upload.php

  • Committer: Bazaar Package Importer
  • Author(s): Jonas Smedegaard
  • Date: 2008-06-22 21:17:13 UTC
  • mto: This revision was merged to the branch mainline in revision 18.
  • Revision ID: james.westby@ubuntu.com-20080622211713-inlv5k4eifxckelr
ImportĀ upstreamĀ versionĀ 1.7.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 * "Support Open Source software. What about a donation today?"
 
13
 * 
 
14
 * File Name: upload.php
 
15
 *      This is the "File Uploader" for PHP.
 
16
 * 
 
17
 * File Authors:
 
18
 *              Frederico Caldeira Knabben (fredck@fckeditor.net)
 
19
 */
 
20
 
 
21
require('config.php') ;
 
22
require('util.php') ;
 
23
 
 
24
// This is the function that sends the results of the uploading process.
 
25
function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
 
26
{
 
27
        echo '<script type="text/javascript">' ;
 
28
        echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
 
29
        echo '</script>' ;
 
30
        exit ;
 
31
}
 
32
 
 
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' ) ;
 
36
 
 
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' ) ;
 
40
 
 
41
// Get the posted file.
 
42
$oFile = $_FILES['NewFile'] ;
 
43
 
 
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 ) ;
 
49
 
 
50
// The the file type (from the QueryString, by default 'File').
 
51
$sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
 
52
 
 
53
// Get the allowed and denied extensions arrays.
 
54
$arAllowed      = $Config['AllowedExtensions'][$sType] ;
 
55
$arDenied       = $Config['DeniedExtensions'][$sType] ;
 
56
 
 
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' ) ;
 
60
 
 
61
$sErrorNumber   = '0' ;
 
62
$sFileUrl               = '' ;
 
63
 
 
64
// Initializes the counter used to rename the file, if another one with the same name already exists.
 
65
$iCounter = 0 ;
 
66
 
 
67
// The the target directory.
 
68
$sServerDir = GetRootPath() . $Config["UserFilesPath"] ;
 
69
 
 
70
while ( true )
 
71
{
 
72
        // Compose the file path.
 
73
        $sFilePath = $sServerDir . $sFileName ;
 
74
 
 
75
        // If a file with that name already exists.
 
76
        if ( is_file( $sFilePath ) )
 
77
        {
 
78
                $iCounter++ ;
 
79
                $sFileName = RemoveExtension( $sOriginalFileName ) . '(' . $iCounter . ').' . $sExtension ;
 
80
                $sErrorNumber = '201' ;
 
81
        }
 
82
        else
 
83
        {
 
84
                move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
 
85
 
 
86
                if ( is_file( $sFilePath ) )
 
87
                {
 
88
                        $oldumask = umask(0) ;
 
89
                        chmod( $sFilePath, 0777 ) ;
 
90
                        umask( $oldumask ) ;
 
91
                }
 
92
                
 
93
                $sFileUrl = $Config["UserFilesPath"] . $sFileName ;
 
94
 
 
95
                break ;
 
96
        }
 
97
}
 
98
 
 
99
SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
 
100
?>
 
 
b'\\ No newline at end of file'