<?php
//文件上传 服务器 从服务器转到七牛云 同时删除服务器文件
$setting = $_W["setting"]["upload"]["image"];
$compressed = !empty($_GPC["compressed"]) ? $_GPC["compressed"] : 0;
$ext = '';
switch ($_FILES["file"]["type"]) {
case "application/x-jpg":
case "image/jpeg":
$ext = "jpg";
break;
case "image/png":
$ext = "png";
break;
case "image/gif":
$ext = "gif";
break;
default:
$result["message"] = "提取资源失败, 资源文件类型错误.";
$return["code"] = 1;
$return["msg"] = "上传资源失败, 资源文件类型错误.";
echo json_encode($return);
exit;
break;
}
if (intval($_FILES["file"]["size"]) > $setting["limit"] * 1024) {
$return["code"] = 1;
$limit = $setting["limit"] * 1024;
$return["msg"] = "上传的媒体文件大于(" . $limit . ")";
echo json_encode($return);
exit;
}
if (empty($_FILES["file"]["name"])) {
$return["code"] = 1;
$return["msg"] = "上传失败, 请选择要上传的文件!";
echo json_encode($return);
exit;
}
if ($_FILES["file"]["error"] != 0) {
$return["code"] = 1;
$return["msg"] = "上传失败, 请重试.";
echo json_encode($return);
exit;
}
$ext = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
$ext = strtolower($ext);
$filename = random(30) . "." . $ext;
/*load()->func('file');
$file = usedcar_file_upload($compressed, $_FILES["file"], "image", $filename);
*/
$filepath = 'images/' . $this->modulename . '/' . $filename;
load()->func('file');
// return json_encode($_FILES['upfile']);
$file=file_upload($_FILES['file'], 'image',$filepath);
$pathname = $file["path"];
// print_r($pathname);
// exit;
if (!empty($_W['setting']['remote']['type'])) { // 判断系统是否开启了远程附件
$remotestatus = file_remote_upload($pathname); //上传图片到远程
if (is_error($remotestatus)) {
message('远程附件上传失败,请检查配置并重新上传');
} else {
$remoteurl = tomedia($pathname); // 远程图片的访问URL
// $pathname 或者 $remoteurl(完整链接)// 本地要存入库的地址
}
}
$return["code"] = 0;
$return["data"]["src"] = $remoteurl;
$return["msg"] = "上传成功";
echo json_encode($return);
exit;
print_r($file);
echo $file;
exit;
?>
|