/** * 上传一张图片 */ public function upload() { $oss = new Oss(); $bucket = 'idaiyan1'; $object = date('y/m/d', time()) . '/zhanglu.jpg'; $path = $_FILES['zhanglu']['tmp_name']; $oss->upload_by_file($bucket, $object, $path); }
/** * 上传至OSS * * @param string $tmpFile 上传文件 */ protected function upload2Oss($tmpFile) { $result = false; try { $oss = new Oss(); $obj = date('Ym') . '/' . $tmpFile; $result = $oss->upload_by_file($this->ossBucket, $obj, $this->tmpPath . $tmpFile); if ($result) { } elseif ($result === false) { $result = 'http://' . $this->ossBucket . '.' . ALIOSS::DEFAULT_OSS_HOST . '/' . $obj; } } catch (\Exception $e) { // TODO: 进行异常处理 } return $result; }