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

41 lines
1.0 KiB
PHP
Raw Normal View History

2024-07-09 16:15:32 +08:00
<?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());
$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();
2024-07-09 16:32:28 +08:00
$file->move(public_path(). $savepath);
2024-07-09 16:15:32 +08:00
$item->save();
return $this->success($savepath);
}
}