"; $object ='image/'.date('y-m',time()).'/'.$newName;//" <您使用的Object名字,注意命名规范>"; (可以写到.env文件中调用) $content = $file["tmp_name"];//上传的文件 try { $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint,false); $ossClient->setTimeout(3600); /* seconds */ $ossClient->setConnectTimeout(10); /* seconds */ // $ossClient->putObject($bucket, $object, $content); // 先把本地的example.jpg上传到指定$bucket, 命名为$object $ossClient->uploadFile($bucket, $object, $content); $signedUrl = $ossClient->signUrl($bucket, $object); $path = explode('?',$signedUrl)[0]; $obj['status'] = true; $obj['path'] = $path; } catch (OssException $e) { $obj['status'] = false; $obj['path'] = ""; print $e->getMessage(); } return $obj; } }