За последние 24 часа нас посетили 50276 программистов и 1758 роботов. Сейчас ищут 1177 программистов ...

FCKeditor и upload картинок

Тема в разделе "Прочие вопросы по PHP", создана пользователем bruno, 25 апр 2007.

  1. bruno

    bruno Активный пользователь

    С нами с:
    9 дек 2006
    Сообщения:
    122
    Симпатии:
    0
    Не знаю в чем проблема. Указан путь по умолчанию /UserFiles/ в конфиг-файлах папок browser и upload. Путь указан верно, поскольку файли, что есть в каталоге UserFiles отображаютса. Когда хочу зааплодить новий, то видает уведомления типа "Файл успешно загружен". Но нифига успешнего нет. Файл на сервак не переносится, хотя на локалхосте все отлично.
    Помогите плз, срочно надо :help:
    Заранее спасибо!
     
  2. Ganzal

    Ganzal Суперстар
    Команда форума Модератор

    С нами с:
    15 мар 2007
    Сообщения:
    9.893
    Симпатии:
    965
    обычно аплоад происходит так
    переданные файлы попадают в tmp сервера а потом их переносят в необходимую папку и раздают необходимые права...
    а как у вас? можно кусочек кода а то отсюда у меня все работает...
     
  3. bruno

    bruno Активный пользователь

    С нами с:
    9 дек 2006
    Сообщения:
    122
    Симпатии:
    0
    upload.php
    PHP:
    1.  
    2. <?
    3. require('config.php') ;
    4. require('util.php') ;
    5.  
    6. // This is the function that sends the results of the uploading process.
    7. function SendResults( $errorNumber, $fileUrl = '', $fileName = '', $customMsg = '' )
    8. {
    9.     echo '<script type="text/javascript">' ;
    10.     echo 'window.parent.OnUploadCompleted(' . $errorNumber . ',"' . str_replace( '"', '\\"', $fileUrl ) . '","' . str_replace( '"', '\\"', $fileName ) . '", "' . str_replace( '"', '\\"', $customMsg ) . '") ;' ;
    11.     echo '</script>' ;
    12.     exit ;
    13. }
    14.  
    15. // Check if this uploader has been enabled.
    16. if ( !$Config['Enabled'] )
    17.     SendResults( '1', '', '', 'This file uploader is disabled. Please check the "editor/filemanager/upload/php/config.php" file' ) ;
    18.  
    19. // Check if the file has been correctly uploaded.
    20. if ( !isset( $_FILES['NewFile'] ) || is_null( $_FILES['NewFile']['tmp_name'] ) || $_FILES['NewFile']['name'] == '' )
    21.     SendResults( '202' ) ;
    22.  
    23. // Get the posted file.
    24. $oFile = $_FILES['NewFile'] ;
    25.  
    26. // Get the uploaded file name extension.
    27. $sFileName = $oFile['name'] ;
    28.  
    29. // Replace dots in the name with underscores (only one dot can be there... security issue).
    30. if ( $Config['ForceSingleExtension'] )
    31.     $sFileName = preg_replace( '/\\.(?![^.]*$)/', '_', $sFileName ) ;
    32.  
    33. $sOriginalFileName = $sFileName ;
    34.  
    35. // Get the extension.
    36. $sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
    37. $sExtension = strtolower( $sExtension ) ;
    38.  
    39. // The the file type (from the QueryString, by default 'File').
    40. $sType = isset( $_GET['Type'] ) ? $_GET['Type'] : 'File' ;
    41.  
    42. // Check if it is an allowed type.
    43. if ( !in_array( $sType, array('File','Image','Flash','Media') ) )
    44.     SendResults( 1, '', '', 'Invalid type specified' ) ;
    45.  
    46. // Get the allowed and denied extensions arrays.
    47. $arAllowed  = $Config['AllowedExtensions'][$sType] ;
    48. $arDenied   = $Config['DeniedExtensions'][$sType] ;
    49.  
    50. // Check if it is an allowed extension.
    51. if ( ( count($arAllowed) > 0 && !in_array( $sExtension, $arAllowed ) ) || ( count($arDenied) > 0 && in_array( $sExtension, $arDenied ) ) )
    52.     SendResults( '202' ) ;
    53.  
    54. $sErrorNumber   = '0' ;
    55. $sFileUrl       = '' ;
    56.  
    57. // Initializes the counter used to rename the file, if another one with the same name already exists.
    58. $iCounter = 0 ;
    59.  
    60. // Get the target directory.
    61. if ( isset( $Config['UserFilesAbsolutePath'] ) && strlen( $Config['UserFilesAbsolutePath'] ) > 0 )
    62.     $sServerDir = $Config['UserFilesAbsolutePath'] ;
    63. else
    64.     $sServerDir = GetRootPath() . $Config["UserFilesPath"] ;
    65.  
    66. if ( $Config['UseFileType'] )
    67.     $sServerDir .= $sType . '/' ;
    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.  
    92.         if ( $Config['UseFileType'] )
    93.             $sFileUrl = $Config["UserFilesPath"] . $sType . '/' . $sFileName ;
    94.         else
    95.             $sFileUrl = $Config["UserFilesPath"] . $sFileName ;
    96.  
    97.         break ;
    98.     }
    99. }
    100.  
    101. SendResults( $sErrorNumber, $sFileUrl, $sFileName ) ;
    102. ?>
    103.  
    config.php
    PHP:
    1.  
    2. <?
    3. global $Config ;
    4.  
    5. // SECURITY: You must explicitelly enable this "uploader".
    6. $Config['Enabled'] = true ;
    7.  
    8. // Set if the file type must be considere in the target path.
    9. // Ex: /userfiles/image/ or /userfiles/file/
    10. $Config['UseFileType'] = false ;
    11.  
    12. // Path to uploaded files relative to the document root.
    13. $Config['UserFilesPath'] = '/gdl/UserFiles/' ;
    14.  
    15. // Fill the following value it you prefer to specify the absolute path for the
    16. // user files directory. Usefull if you are using a virtual directory, symbolic
    17. // link or alias. Examples: 'C:\\MySite\\userfiles\\' or '/root/mysite/userfiles/'.
    18. // Attention: The above 'UserFilesPath' must point to the same directory.
    19. $Config['UserFilesAbsolutePath'] ='' ;
    20.  
    21. // Due to security issues with Apache modules, it is reccomended to leave the
    22. // following setting enabled.
    23. $Config['ForceSingleExtension'] = true ;
    24.  
    25. $Config['AllowedExtensions']['File']    = array() ;
    26. $Config['DeniedExtensions']['File']     = array('html','htm','php','php2','php3','php4','php5','phtml','pwml','inc','asp','aspx','ascx','jsp','cfm','cfc','pl','bat','exe','com','dll','vbs','js','reg','cgi','htaccess','asis') ;
    27.  
    28. $Config['AllowedExtensions']['Image']   = array('jpg','gif','jpeg','png') ;
    29. $Config['DeniedExtensions']['Image']    = array() ;
    30.  
    31. $Config['AllowedExtensions']['Flash']   = array('swf','fla') ;
    32. $Config['DeniedExtensions']['Flash']    = array() ;
    33. ?>
    34.  
    util.php
    PHP:
    1.  
    2. <?
    3. function RemoveExtension( $fileName )
    4. {
    5.     return substr( $fileName, 0, strrpos( $fileName, '.' ) ) ;
    6. }
    7.  
    8. function GetRootPath()
    9. {
    10.     $sRealPath = realpath( './' ) ;
    11.  
    12.     $sSelfPath = $_SERVER['PHP_SELF'] ;
    13.     $sSelfPath = substr( $sSelfPath, 0, strrpos( $sSelfPath, '/' ) ) ;
    14.  
    15.     return substr( $sRealPath, 0, strlen( $sRealPath ) - strlen( $sSelfPath ) ) ;
    16. }
    17. ?>
    18.  
     
  4. evll

    evll Активный пользователь

    С нами с:
    3 май 2007
    Сообщения:
    15
    Симпатии:
    0
    Адрес:
    Lithuania
    Проверьте разрешения на UserFiles и на всех субдирах. Попробуйте для начала с 777.
     
  5. Shatalinalex

    Shatalinalex Активный пользователь

    С нами с:
    7 мар 2006
    Сообщения:
    92
    Симпатии:
    0
    Адрес:
    Нижний Новгород
    В FCKeditor возможно чтобы он грузил не в заданые папки Files,Image итд а просто в мою директорию картинок

    допустим я указал в конфигах $Config['UserFilesPath'] = '/shatalinalex/file/' ; и все

    а он создает Files,Image их в /shatalinalex/file/ ?? Возможно ли этого как то избежать?