UEditor 图片上传配置(PHP)

修改config.php文件第11,12行
在这里插入图片描述

线上

    "imageUrlPrefix": "http://www.leition.com/", /* 图片访问路径前缀 */
    "imagePathFormat": "upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */

注意编码格式,不要用记事本修改,直接代码编辑器(比如本人用的Hbuilder)里修改好后复制粘贴替换掉就OK了
线下

    "imageUrlPrefix": "", /* 图片访问路径前缀 */
    "imagePathFormat": "/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
ueditor 的分片上传功能需要在后端进行配置。以下是一个简单的 PHP 后端配置示例: 1. 在 ueditor/php/config.json 文件中,将 "imageAllowFiles" 和 "fileAllowFiles" 分别改为 "*",表示允许上传任何类型的文件。 2. 在 ueditor/php/config.php 文件中,添加如下代码: ```php // 分片上传配置 $config['chunked'] = true; // 开启分片上传 $config['chunkSize'] = 2 * 1024 * 1024; // 每个分片的大小,这里设置为2MB $config['savePath'] = __DIR__ . '/uploads/'; // 文件保存路径,需要确保该目录存在,并有写入权限 $config['rootPath'] = '/uploads/'; // 文件访问根路径,需要根据实际情况修改 ``` 3. 在 ueditor/php/controller.php 文件中,添加如下代码: ```php // 分片上传处理 if ($action == 'uploadfile' && $CONFIG['chunked']) { $uploader = new \UploaderChunked($config); $result = $uploader->doUpload(); return json_encode($result); } ``` 4. 在 ueditor/php/Uploader.class.php 文件中,添加如下代码: ```php // 分片上传处理类 class UploaderChunked extends Uploader { public function __construct($config) { parent::__construct($config); } public function doUpload() { if ($this->file['error'] === UPLOAD_ERR_OK) { $tmpName = $this->file['tmp_name']; $fileName = $this->file['name']; $chunk = isset($_POST['chunk']) ? intval($_POST['chunk']) : 0; $chunks = isset($_POST['chunks']) ? intval($_POST['chunks']) : 1; $filePath = $this->getFilePath($fileName); $chunkFile = $filePath . '_' . $chunk . '.part'; // 移动上传的分片文件 move_uploaded_file($tmpName, $chunkFile); // 检查是否上传完成 for ($i=0; $i<$chunks; $i++) { $partFile = $filePath . '_' . $i . '.part'; if (!file_exists($partFile)) { return $this->getErrorMessage('missing_upload_chunk'); } } // 合并分片文件 $fp = fopen($filePath, 'wb'); if ($fp === false) { return $this->getErrorMessage('open_file_failed'); } for ($i=0; $i<$chunks; $i++) { $partFile = $filePath . '_' . $i . '.part'; $data = file_get_contents($partFile); fwrite($fp, $data); unlink($partFile); } fclose($fp); // 返回成功信息 $fileSize = filesize($filePath); return array( "state" => "SUCCESS", "url" => $this->config['rootPath'] . $this->getFileName($fileName), "title" => $fileName, "original" => $fileName, "size" => $fileSize, "type" => '.' . pathinfo($fileName, PATHINFO_EXTENSION) ); } else { return $this->getErrorMessage($this->file['error']); } } } ``` 以上代码实现了将上传的文件分成多个片段进行上传,并在后端进行合并,最终生成完整的文件。需要注意的是,这里仅提供了一个简单的示例,实际情况下可能需要根据具体需求进行修改。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值