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

42 lines
1.1 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)
{
2024-10-21 17:14:32 +08:00
return $this->success('/uploads/1/20241019175205021482/7418af88ebc0333ef4bee0a0a2cc7de0.jpg');
2024-07-09 16:15:32 +08:00
$file = $request->file("file");
2024-08-09 15:21:06 +08:00
2024-07-09 16:15:32 +08:00
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;
2024-07-09 16:34:14 +08:00
$item->filesize = 0;
2024-07-09 16:15:32 +08:00
$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);
}
}