在html页面添加
UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
UE.Editor.prototype.getActionUrl = function(action) {
if (action == 'uploadimage') {
return SITE_URL+"/index.php?app=comupload&act=test";
} else {
return this._bkGetActionUrl.call(this, action);
}
}
这个是指定的上传路径 SITE_URL+"/index.php?app=comupload&act=test";
然后test如下,保持上传的文件,注意的是返回格式,格式参照
$arr = array(
'url' => $file_path,
'original' => $files['name'],
'size' => $files['size'],
'state' => 'SUCCESS',
'title' => $filename,
'type' => $files['type'],
);
echo json_encode($arr);
function test(){
import('image.func');
import('uploader.lib');
$uploader = new Uploader();
$files = $_FILES['upfile'];
if ($files['error'] === UPLOAD_ERR_OK) {
if (!$files['size']) {
return;
}
/* 处理文件上传 */
$file = array(
'name' => $files['name'],
'type' => $files['type'],
'tmp_name' => $files['tmp_name'],
'size' => $files['size'],
'error' => $files['error'],
);
$uploader->addFile($file);
if (!$uploader->file_info()) {
$data = current($uploader->get_error());
$res = Lang::get($data['msg']);
$this->view_iframe();
echo "<script type='text/javascript'>alert('{$res}');</script>";
return false;
}
$uploader->root_dir(ROOT_PATH);
$dirname = '';
$store_id = $this->visitor->get('user_id');
$dirname = 'data/files/store_' . $this->store_id . '/goods_' . (time() % 200);
$filename = $uploader->random_filename();
$file_path = $uploader->save($dirname, $filename);
if ($file_path != '') {
$arr = array(
'url' => $file_path,
'original' => $files['name'],
'size' => $files['size'],
'state' => 'SUCCESS',
'title' => $filename,
'type' => $files['type'],
);
echo json_encode($arr);
exit;
} else {
echo 'error';exit;
}
}
}