3 PHP Connector for the FCKEditor v2 File Manager
4 Written By Grant French, UK, Sept 2004
7 FCKEditor - By Frederico Caldeira Knabben
8 http://www.fckeditor.net
11 Implements the FileUpload command,
12 Checks the file uploaded is allowed,
13 then moves it to the user data area.
15 2008.6.8 modified by naoki hirata
16 2009.2.10 mbstringなしでも実行できるように修正 by naoki hirata
19 class FileUpload extends command {
21 $disp = $this->_run();
23 header ("content-type: text/html; charset=UTF-8");
25 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
28 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
29 <title>Upload Complete</title>
32 <script type="text/javascript">
33 window.parent.frames['frmUpload'].OnUploadCompleted(<?php echo $disp; ?>) ;
41 global $gOpeLogManager;
43 if (sizeof($_FILES) == 0){ // アップロードファイルがないとき
44 return "202";// fixed by naoki on 2008/12/9.
47 $errCode = $_FILES['NewFile']['error'];
48 if($errCode !== UPLOAD_ERR_OK){
49 $gOpeLogManager->writeError(__METHOD__, 'ファイルブラウザからのアップロードに失敗しました。エラーコード: ' . $errCode, 3001);
52 $typeconfig = $this->fckphp_config['ResourceAreas'][$this->type];
54 if (! array_key_exists("NewFile", $_FILES)) {
55 return "203"; //No parametor
58 if ($_FILES['NewFile']['size'] > ($typeconfig['MaxSize'] * 1024)) {
59 return "204,'{$typeconfig['MaxSize']}'"; //Too big
62 $filename = $_FILES['NewFile']['name'];
64 if ($filename == '') {
68 if (function_exists('mb_ereg')){
69 if (mb_ereg($this->fckphp_config['DisableName'], $filename)) {
73 if (ereg($this->fckphp_config['DisableName'], $filename)) {
78 if (function_exists('mb_ereg')){
79 if (mb_ereg($this->fckphp_config['DisableChars'], $filename)) {
83 if (ereg($this->fckphp_config['DisableChars'], $filename)) {
88 if (function_exists('mb_strrpos')){
89 $lastdot = mb_strrpos($filename, ".");
90 if ($lastdot === false) {
91 return "205"; //No ext
94 $ext = mb_substr($filename, ($lastdot + 1));
95 $filename = mb_substr($filename, 0, $lastdot);
97 $lastdot = strrpos($filename, ".");
98 if ($lastdot === false) {
99 return "205"; //No ext
102 $ext = substr($filename, ($lastdot + 1));
103 $filename = substr($filename, 0, $lastdot);
106 if (! in_array(strtolower($ext), $typeconfig['AllowedExtensions'])) {
107 return "206,'{$ext}'"; //Disallowed file extension
110 if (! $this->mapFolder($this->actual_cwd)) {
111 return 110; //Unknown error
118 if ($this->fckphp_config['DiskQuota']['Global'] != -1) {
119 foreach ($this->fckphp_config['ResourceTypes'] as $resType) {
120 //$path = "{$this->fckphp_config['UserFilesPath']}/{$resType}";
121 $path = $this->fckphp_config['UserFilesPath'] . '/' . strtolower($resType); // ディレクトリ名を英小文字に設定 by naoki
123 if (is_dir($this->path($path))) {
124 $dirSizes[$resType] = $this->getDirSize($path);
126 if ($dirSizes[$resType] === false) {
127 return "207,'{$resType}'"; //Unable to determine the size of a folder
130 $dirSizes[$resType] = 0;
133 $globalSize += $dirSizes[$resType];
136 $globalSize += $_FILES['NewFile']['size'];
138 if ($globalSize > ($this->fckphp_config['DiskQuota']['Global'] * 1024 * 1024)) {
139 return "208,'{$this->fckphp_config['DiskQuota']['Global']}'"; //You are over the global disk quota
143 if ($typeconfig['DiskQuota'] != -1) {
144 if ($this->fckphp_config['DiskQuota']['Global'] == -1) {
145 //$path = "{$this->fckphp_config['UserFilesPath']}/{$this->type}";
146 $path = $this->fckphp_config['UserFilesPath'] . '/' . strtolower($this->type); // ディレクトリ名を英小文字に設定 by naoki
148 if (is_dir($this->path($path))) {
149 $dirSizes[$this->type] = $this->getDirSize($path);
151 if ($dirSizes[$this->type] === false) {
152 return "207,'{$this->type}'"; //Unable to determine the size of a folder
155 $dirSizes[$this->type] = 0;
159 if (($dirSizes[$this->type] + $_FILES['NewFile']['size']) > ($typeconfig['DiskQuota'] * 1024 * 1024)) {
160 return "209,'{$typeconfig['DiskQuota']}'"; //You are over the disk quota for this resource type
167 for ($i = 1; $i < $this->fckphp_config['AvailableMax']; $i++) {
168 if (! file_exists($this->path("{$this->actual_cwd}{$unique}.{$ext}"))) {
173 $unique = "{$filename}({$i})";
181 if (! is_uploaded_file($_FILES['NewFile']['tmp_name'])) {
185 if (! move_uploaded_file($_FILES['NewFile']['tmp_name'], $this->path("{$this->actual_cwd}{$unique}.{$ext}"))) {
186 $path = $this->path("{$this->actual_cwd}");
187 //$gOpeLogManager->writeError(__METHOD__, 'ファイルのアップロードに失敗しました。ディレクトリに書き込み権限がない可能性があります。ディレクトリ: ' . $path, 3001);
188 return "212,'{$path}'";
191 chmod($this->path("{$this->actual_cwd}{$unique}.{$ext}"), 0777);
193 return ($unique == $filename) ? "0" : "1,'". "{$unique}.{$ext}'";
196 function getDirSize($dir) {
197 if (($dh = @opendir($this->path($dir))) === false) {
203 while ($file = @readdir($dh)) {
204 if ($file == ".") continue;
205 if ($file == "..") continue;
207 if (function_exists('mb_convert_encoding')){
208 $file = mb_convert_encoding($file, $this->fckphp_config['FileEncoding'], 'UTF-8');
211 if (is_dir($this->path("{$dir}/{$file}"))) {
212 $tmp_dirSize = $this->getDirSize("{$dir}/{$file}");
214 if ($tmp_dirSize === false) {
219 $dirSize += $tmp_dirSize;
224 $dirSize += filesize($this->path("{$dir}/{$file}"));