vm3857: 1 uncaught syntaxerror: unexpected identifier at object.success(easyupload.js: 310) at j(jquery - 1.11 .1.min.js: 2) at object.firewith[as resolvewith](jquery - 1.11 .1.min.js: 2) at x(jquery - 1.11 .1.min.js: 4) at xmlhttprequest.b(jquery - 1.11 .1.min.js: 4)
页面报的错误
public function uploadwebimg() { //dump($_files); $uploadfilename = $_files['upload']['name']; $uploadfilesize = $_files['upload']['size']; if ($uploadfilesize > 1024 * 5 * 1000) { echo json_encode(["code" => 100, "msg" => "图片大小不能超过5m"]); exit; } $extensions = array("jpg", "bmp", "gif", "png", "jpeg"); $extension = pathinfo($uploadfilename, pathinfo_extension); if (in_array($extension, $extensions)) { $uploadpath = "./upload/images/web/"; $uuid = str_replace('.', '', uniqid("", true)). ".".$extension; $desname = $uploadpath.$uuid; //dump($_files); $tag = move_uploaded_file($_files['upload']['tmp_name'], $desname); //dump($tag);exit; $previewname = '/upload/images/web/'.$uuid; echo json_encode(["code" => 200, "msg" => $previewname]); } else { echo json_encode(["code" => 100, "msg" => "文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)"]); } }
部分图片不能上传到服务器啊 所以移动文件没有用 tmp_name 是空的 这个是浏览器bug吗? 有的图片能上传上去 不知道怎么回事 这是我的后台php 代码 js中 filename 改成了 upload 还有楼上的 关于 code的我也改了 js文件 觉得有用的可以看看 ,反正感觉有bug
这是Laravel 框架
public function Uploads(Request $request) { if ($request - > file('file')) { //判断文件大小 $size = $request - > file('file') - > getSize(); $images = $request - > file('file'); $filedir = "uploads/course"; $imagesName = $images - > getClientOriginalName(); $extension = $images - > getClientOriginalExtension(); $newImagesName = md5(time()).random_int(5, 5). ".".$extension; $images - > move($filedir, $newImagesName); //6、使用move方法移动文件. return response() - > json([ 'status' => 'success', 'src' => $filedir. '/'.$newImagesName, 'code' => '200' ]); } else { return response() - > json([ 'status' => 'error', 'code' => 0, 'msg' => '发生未知错误' ]); } }