Source for file upload.php

Documentation is available at upload.php

  1. <?php 
  2. /*
  3.  * FCKeditor - The text editor for internet
  4.  * Copyright (C) 2003-2006 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 extension.
  45. $sFileName $oFile['name';
  46.  
  47. // Replace dots in the name with underscores (only one dot can be there... security issue).
  48. if $Config['ForceSingleExtension')
  49.     $sFileName preg_replace'/\\.(?![^.]*$)/''_'$sFileName ;
  50.  
  51. $sOriginalFileName $sFileName ;
  52.  
  53. // Get the extension.
  54. $sExtension substr$sFileNamestrrpos($sFileName'.') ) ;
  55. $sExtension strtolower$sExtension ;
  56.  
  57. // The the file type (from the QueryString, by default 'File').
  58. $sType = isset$_GET['Type'$_GET['Type''File' ;
  59.  
  60. // Check if it is an allowed type.
  61. if !in_array$sTypearray('File','Image','Flash','Media') ) )
  62.     SendResults1'''''Invalid type specified' ;
  63.  
  64. // Get the allowed and denied extensions arrays.
  65. $arAllowed    $Config['AllowedExtensions'][$sType;
  66. $arDenied    $Config['DeniedExtensions'][$sType;
  67.  
  68. // Check if it is an allowed extension.
  69. if ( ( count($arAllowed&& !in_array$sExtension$arAllowed ) ) || count($arDenied&& in_array$sExtension$arDenied ) ) )
  70.     SendResults'202' ;
  71.  
  72. $sErrorNumber    '0' ;
  73. $sFileUrl        '' ;
  74.  
  75. // Initializes the counter used to rename the file, if another one with the same name already exists.
  76. $iCounter ;
  77.  
  78. // The the target directory.
  79. if isset$Config['UserFilesAbsolutePath'&& strlen$Config['UserFilesAbsolutePath')
  80.     $sServerDir $Config['UserFilesAbsolutePath';
  81. else 
  82.     $sServerDir GetRootPath($Config["UserFilesPath";
  83.  
  84. while true )
  85. {
  86.     // Compose the file path.
  87.     $sFilePath $sServerDir $sFileName ;
  88.  
  89.     // If a file with that name already exists.
  90.     if is_file$sFilePath ) )
  91.     {
  92.         $iCounter++ ;
  93.         $sFileName RemoveExtension$sOriginalFileName '(' $iCounter ').' $sExtension ;
  94.         $sErrorNumber '201' ;
  95.     }
  96.     else
  97.     {
  98.         move_uploaded_file$oFile['tmp_name']$sFilePath ;
  99.  
  100.         if is_file$sFilePath ) )
  101.         {
  102.             $oldumask umask(0;
  103.             chmod$sFilePath0777 ;
  104.             umask$oldumask ;
  105.         }
  106.         
  107.         $sFileUrl $Config["UserFilesPath"$sFileName ;
  108.  
  109.         break ;
  110.     }
  111. }
  112.  
  113. SendResults$sErrorNumber$sFileUrl$sFileName ;
  114. ?>

Documentation generated on Sun, 09 Mar 2008 23:53:39 -0300 by phpDocumentor 1.4.0

SourceForge.net Logo Support This Project