private function Uploader::upFile in UEditor - 百度编辑器 7.2
Same name and namespace in other branches
- 7.3 includes/Uploader.class.inc \Uploader::upFile()
上传文件的主处理方法
Return value
mixed
1 call to Uploader::upFile()
- Uploader::__construct in includes/
Uploader.class.inc - 构造函数
File
- includes/
Uploader.class.inc, line 71
Class
- Uploader
- Created by JetBrains PhpStorm. User: taoqili Date: 12-7-18 Time: 上午11: 32 UEditor编辑器通用上传类
Code
private function upFile() {
$file = $this->file = $_FILES[$this->fileField];
if (!$file) {
$this->stateInfo = $this
->getStateInfo("ERROR_FILE_NOT_FOUND");
return;
}
if ($this->file['error']) {
$this->stateInfo = $this
->getStateInfo($file['error']);
return;
}
else {
if (!file_exists($file['tmp_name'])) {
$this->stateInfo = $this
->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
return;
}
else {
if (!is_uploaded_file($file['tmp_name'])) {
$this->stateInfo = $this
->getStateInfo("ERROR_TMPFILE");
return;
}
}
}
$this->oriName = $file['name'];
$this->fileSize = $file['size'];
$this->fileType = $this
->getFileExt();
$this->fullName = $this
->getFullName();
$this->savePath = ueditor_get_savepath($this->fullName);
$this->filePath = $this
->getFilePath();
$this->fileName = $this
->getFileName();
$dirname = dirname($this->filePath);
//检查文件大小是否超出限制
if (!$this
->checkSize()) {
$this->stateInfo = $this
->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//检查是否不允许的文件格式
if (!$this
->checkType()) {
$this->stateInfo = $this
->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
return;
}
//创建目录失败
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this
->getStateInfo("ERROR_CREATE_DIR");
return;
}
else {
if (!is_writeable($dirname)) {
$this->stateInfo = $this
->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
}
}
// Load the files contents
$imagedata = file_get_contents($file["tmp_name"]);
$filedata = $this
->savefileToDrupal($imagedata, $this->savePath);
//移动文件
if (is_object($filedata)) {
//移动成功
$success = FALSE;
$use_watermark = variable_get('ueditor_watermark', 0);
if ($use_watermark && $this->config['type'] == 'image') {
$success = $this
->addWatermark($this->filePath);
}
else {
$success = TRUE;
}
if ($success === TRUE) {
$this->stateInfo = $this->stateMap[0];
}
else {
$this->stateInfo = $this
->getStateInfo($success);
}
}
else {
//移动失败
$this->stateInfo = $this
->getStateInfo("ERROR_FILE_MOVE");
}
}