上传图片

admin1年前Laravel417

public function image()
{
   $obFile = request()->file('image');
   if (!$obFile) {
       return $this->error('请上传文件');
   }
   $sOldName = $obFile->getClientOriginalName();//原名
   $sFileType = $obFile->getClientMimeType(); //文件类型
   $sExtensionName = $obFile->getClientOriginalExtension();//扩展名
   $sPath = $obFile->getRealPath();    //文件存储的位置路径
   $arrAllowExtension = ['jpg', 'png', 'jpeg', 'gif', 'bmp'];
   if (!in_array($sExtensionName, $arrAllowExtension)) {
       return $this->error('必须是 jpeg, bmp, png, gif chan');
   }
   //组装文件存储的位置和自定义文件名
   $path = "upload/goods/" . date("Ymd");
   if (!is_dir($path)) { //判断目录是否存在 不存在就创建
       mkdir($path, 0777, true);
       chmod($path, 0777);
   }
   $imageName = "p_" . date("His", time()) . "_" . rand(1111, 9999);
   $sFileName = 'goods/' . date('Ymd') . '/' . $imageName . '.' . $sExtensionName;
   //调用laravel系统封装好的函数把图片存储到指定文件下
   $bRet = Storage::disk('admin')->put($sFileName, file_get_contents($sPath));
   if (!$bRet) {
       return $this->error('上传失败');
   }
   return $this->success('ok', $this->domain() . '/upload/' . $sFileName);
}

相关文章

微信退款v3

/** * 微信 退款 操作 */ public function refund($out_trade_no, $refund_money) { $time = time();...

修改密码

public function setpass(){    $mobile = request()->input('mobile');   &nbs...

用户注册账号

public function register(){    $mobile = request()->input('mobile');   &nb...

微信退款v2

/** * 微信 退款 操作 */ public function refund($out_trade_no, $total_fee) { $parma =...

获取微信的Token

 public function Token()    {        $this->path = __DIR__ . &...

laravel 加cache锁

use Illuminate\Support\Facades\Redis; use Illuminate\Support\Facades\Cache; $lock = Ca...