时间:2021-07-01 10:21:17 帮助过:38人阅读
function ajaxfile() {
foreach (lib_request::$files as $filename => $value) {
$picname = lib_request::$files[$filename]['name'];
$picsize = lib_request::$files[$filename]['size'];
if ($picname != "") {
if ($picsize > 1024000) {
echo json_encode(array(
'code' => '-1',
'title' => '图片上传',
'msg' => '图片大小不能超过1M'
));
exit();
}
$type = get_extension($picname);
if ($type != "gif" && $type != "jpg" && $type != "jpeg" && $type != "png") {
echo json_encode(array(
'code' => '-1',
'title' => '图片上传',
'msg' => '图片格式不对!'
));
exit();
}
$upload_path = '/up';
$rand = rand(100, 999);
$pics = date("YmdHis") . $rand . '.' . $type;
$dir = date('/YmdH/');
$pic_path = $upload_path . $dir;
$pic_url = $pic_path . $pics;
if (!file_exists(PATH_ROOT . $pic_path)) {
creatFolder(PATH_ROOT . $pic_path);
}
$PATH_ROOT = PATH_ROOT . $pic_url;
move_uploaded_file(lib_request::$files[$filename]['tmp_name'], $pic_path);
if (request('type') == 'goods') {
makeThumbnail($pic_path, $pic_path . '_290x290.jpg', 290, 190);
}
}
$arr[$filename] = array(
'name' => $picname,
'pic' => $pic_url,
'size' => $picsize
);
}
echo json_encode($arr);
exit();
}
$pic_url = ‘http://www.xxxx.com/’.$pic_path . $pics;