php - CKFinder 3 无法上传文件

标签 php file-upload ckeditor ckfinder file-browser

我对 CKFinder 3 的实现有疑问。 一切正常,除了上传文件和图像。

当我点击上传时。我在我的电脑上选择了一个文件,然后它给我一条错误消息,名为:上传完成但有错误。当我单击“详细信息”时,它显示:无效文件。

在我的调试文件中它输出这个:

[02-Sep-2015 16:35:27 Europe/Berlin] PHP Notice:  Undefined index: dirname in ckfinder/core/connector/php/vendor/cksource/ckfinder/src/CKSource/CKFinder/Filesystem/File/UploadedFile.php on line 70

有人可以帮我解决这个问题吗?

这是我的CKFinder的config.php代码:

<?php

/*
 * CKFinder Configuration File
 *
 * For the official documentation visit http://docs.cksource.com/ckfinder3-php/
 */

/*============================ PHP Error Reporting ====================================*/
// http://docs.cksource.com/ckfinder3-php/debugging.html

// Production
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
ini_set('display_errors', 0);

// Development
// error_reporting(E_ALL);
// ini_set('display_errors', 1);

/*============================ General Settings =======================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html

$config = array();

/*============================ Enable PHP Connector HERE ==============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_authentication

$config['authentication'] = function() {
    return true;
};

/*============================ License Key ============================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_licenseKey

$config['licenseName'] = '';
$config['licenseKey']  = '';

/*============================ CKFinder Internal Directory ============================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_privateDir

$config['privateDir'] = array(
    'backend' => 'default',
    'tags'   => '.ckfinder/tags',
    'logs'   => '.ckfinder/logs',
    'cache'  => '.ckfinder/cache',
    'thumbs' => '.ckfinder/cache/thumbs',
);

/*============================ Images and Thumbnails ==================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_images

$config['images'] = array(
    'maxWidth'  => 1600,
    'maxHeight' => 1200,
    'quality'   => 80,
    'sizes' => array(
        'small'  => array('width' => 480, 'height' => 320, 'quality' => 80),
        'medium' => array('width' => 600, 'height' => 480, 'quality' => 80),
        'large'  => array('width' => 800, 'height' => 600, 'quality' => 80)
    )
);

/*=================================== Backends ========================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_backends

$config['backends'][] = array(
    'name'         => 'default',
    'adapter'      => 'local',
    'baseUrl'      => '/VVBBC/assets/img/uploads/',
//  'root'         => '', // Can be used to explicitly set the CKFinder user files directory.
    // 'chmodFiles'   => 0777,
    // 'chmodFolders' => 0755,
    // 'filesystemEncoding' => 'UTF-8',
);

/*================================ Resource Types =====================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_resourceTypes

$config['defaultResourceTypes'] = '';

$config['resourceTypes'][] = array(
    'name'              => 'Files', // Single quotes not allowed.
    'directory'         => 'files',
    'maxSize'           => 0,
    'allowedExtensions' => '7z,aiff,asf,avi,bmp,csv,doc,docx,fla,flv,gif,gz,gzip,jpeg,jpg,mid,mov,mp3,mp4,mpc,mpeg,mpg,ods,odt,pdf,png,ppt,pptx,pxd,qt,ram,rar,rm,rmi,rmvb,rtf,sdc,sitd,swf,sxc,sxw,tar,tgz,tif,tiff,txt,vsd,wav,wma,wmv,xls,xlsx,zip',
    'deniedExtensions'  => '',
    'backend'           => 'default'
);

$config['resourceTypes'][] = array(
    'name'              => 'Images',
    'directory'         => 'images',
    'maxSize'           => 0,
    'allowedExtensions' => 'bmp,gif,jpeg,jpg,png',
    'deniedExtensions'  => '',
    'backend'           => 'default'
);

/*================================ Access Control =====================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_roleSessionVar

$config['roleSessionVar'] = 'CKFinder_UserRole';

// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_accessControl
$config['accessControl'][] = array(
    'role'                => '*',
    'resourceType'        => '*',
    'folder'              => '/',

    'FOLDER_VIEW'         => true,
    'FOLDER_CREATE'       => true,
    'FOLDER_RENAME'       => true,
    'FOLDER_DELETE'       => true,

    'FILE_VIEW'           => true,
    'FILE_UPLOAD'         => true,
    'FILE_RENAME'         => true,
    'FILE_DELETE'         => true,

    'IMAGE_RESIZE'        => true,
    'IMAGE_RESIZE_CUSTOM' => true
);


/*================================ Other Settings =====================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html

$config['overwriteOnUpload'] = false;
$config['checkDoubleExtension'] = true;
$config['disallowUnsafeCharacters'] = false;
$config['secureImageUploads'] = false;
$config['checkSizeAfterScaling'] = true;
$config['htmlExtensions'] = array('html', 'htm', 'xml', 'js');
$config['hideFolders'] = array('.*', 'CVS', '__thumbs');
$config['hideFiles'] = array('.*');
$config['forceAscii'] = false;
$config['xSendfile'] = false;

// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_debug
$config['debug'] = false;

/*==================================== Plugins ========================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_plugins

$config['pluginsDirectory'] = __DIR__ . '/plugins';
$config['plugins'] = array();

/*================================ Cache settings =====================================*/
// http://docs.cksource.com/ckfinder3-php/configuration.html#configuration_options_cache

$config['cache'] = array(
    'imagePreview' => 24 * 3600,
    'thumbnails'   => 24 * 3600 * 365
);

/*============================== End of Configuration =================================*/

// Config must be returned - do not change it.
return $config;

最佳答案

我能够在 OSX 上重现这个问题。在此版本的 XAMPP 中访问预配置的临时目录时出现问题。这可以通过 php.ini 中的 sys_temp_dir 指令进行更改,但也可以在新版本的 CKFinder 中进行配置。

请尝试以下操作:

  1. this link 下载 CKFinder 的预发布 3.1 版本.
  2. 打开 CKFinder 连接器配置 (config.php) 并在文件底部查找 tempDirectory 选项。
  3. sys_get_temp_dir() 替换为您的 XAMPP temp 目录路径。对我来说是 /Applications/XAMPP/xamppfiles/temp/

所以改为:

$config['tempDirectory'] = sys_get_temp_dir();

应该有:

$config['tempDirectory'] = '/Applications/XAMPP/xamppfiles/temp/';

配置其他必需的 CKFinder 选项,例如身份验证。上传现在应该可以正常工作了。

另一种解决方案:

您可以在 php.ini 中设置全局 sys_temp_dir 指令,而不是像上面描述的那样在应用程序级别更改它。为此,将以下行添加到 /Applications/XAMPP/xamppfiles/etc/php.ini:

sys_temp_dir = "/Applications/XAMPP/xamppfiles/temp/"

然后在 XAMPP 中重新启动 Apache。之后可以使用 sys_get_temp_dir() 获取临时目录位置,因此无需更改 CKFinder 配置中的 tempDirectory 选项。

关于php - CKFinder 3 无法上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32356291/

相关文章:

python : upload my own files into my drive using Pydrive library

ckeditor - 如何使用CKEditor的removeMenuItem()函数?

javascript - 如何使用 SweetAlert2 重置 CKeditor4

php - 如何嵌入适用于所有网络和移动浏览器的 PDF

php - JavaScript 数组到 PHP 数组然后在 PHP 中处理并返回

php - 检查自日期以来耗时是否超过 X 天

PHP 输出数组到 SELECT mysql

angularjs - Node.JS - 发布上传文件而不保存

Java通过ftp上传文件零字节错误

javascript - 在没有 CKEDITOR 的情况下打开 CKEDITOR 对话框