travel/service/app/admin/controller/UploadController.php

41 lines
1.0 KiB
PHP

<?php
namespace app\admin\controller;
use app\model\Admins;
use app\model\Uploads;
use app\model\Backs;
use app\model\Finances;
use app\model\Onlines;
use app\model\Orders;
use DateTime;
use Qiniu\Auth;
use support\Log;
use support\Redis;
use support\Request;
class UploadController extends base
{
public function index(Request $request)
{
$file = $request->file("file");
if (!$file->isValid()) {
return $this->error(400, 'upload fail, code=' . $file->getUploadErrorCode());
}
$now = date_create();
$savepath = sprintf("/uploads/%d/%s/%s", $request->admin->id, $now->format("YmdHisu"), $file->getUploadName());
$file->move(public_path(). $savepath);
$item = new Uploads();
$item->admin_id = $request->admin->id;
$item->filesize = $file->getSize();
$item->filepath = $savepath;
$item->mime = $file->getUploadMimeType();
$item->create_at = $now->getTimestamp();
$item->save();
return $this->success($savepath);
}
}