apicloud 图片上传

前端之家收集整理的这篇文章主要介绍了apicloud 图片上传前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<h3 style="Box-sizing: border-Box; font-weight: 500; line-height: 1.1; color: rgb(51,51,51); margin-top: 1.6em; margin-bottom: 0.6em; font-size: 20px; white-space: normal;"><span style="Box-sizing: border-Box; font-weight: 700;">apicloud 图片上传,ajax图片上传

页面触发标签

  1. Meta charset="utf-8">
  2.     <Meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  3.     <Meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
  4.     上传function save(data)
  5. {
  6.   api.ajax({
  7.       url: 'http://192.168.0.163:81/api-v1/driver/task/receipt',      method: 'post',      report:true,//回调上传进度
  8.       data: {files:{file:data},values:{id:39}}
  9.       }, err) {
  10.       if (ret) {
  11.         //成功 可加载回调进度
  12.         console.log(JSON.stringify(ret));
  13.       } else {
  14.         console.log(JSON.stringify(err));
  15.       }
  16.   });
  17. }
  18. </script>
  19. </body>
  20. </html>

laravel框架:

  1.  * 上传图片
  2.  */
  3. public function orderReceiptUpload($request)
  4. {
  5.     $obj = new \stdClass();
  6.     if( $request->file('file') == false )
  7.     {
  8.         $obj->status = 1;
  9.         $obj->msg = '上传失败';
  10.         return $obj;
  11.     }
  12.     //检验文件类型
  13.     $fileTypes = array('image/jpeg','image/png','image/jpg');
  14.     if(!in_array($request->file('file')->getMimeType(),$fileTypes)) {
  15.         $obj->status = 1;
  16.         $obj->msg = '文件格式不正确';
  17.         return $obj;
  18.     }
  19.     //检验大小
  20.     $fileSize= $request->file('file')->getSize();
  21.     if(!$request->file('file')->getSize() || $fileSize>2097152 )
  22.     {
  23.         $obj->status = 1;
  24.         $obj->msg = $fileSize."图片大小不能低于0或超过2048kb";
  25.         return $obj;
  26.     }
  27.     try {
  28.         $file = $request->file('file');

  29.         // 检验一下上传文件是否有效.

  30.         if($file->isValid())

  31.         {

  32.             //上传文件的后缀.

  33.             $fix = $file->getClientOriginalExtension();

  34.             $newName = md5(date("Y-m-d H:i:s")).".".$fix;

  35.             $dir = '/uploads/'.date("Y-m-d").'/';

  36.             $file->move(public_path().$dir,$newName);

  37.         }

  38.         $obj->status = 0;

  39.         $obj->msg = '上传成功';

  40.         return $obj;

  41.     } catch (\Exception $e)

  42.     {

  43.         $obj->status = 1;

  44.         $obj->msg = '上传失败';

  45.         return $obj;

  46.     }

  47. }


猜你在找的jQuery相关文章