美文网首页
[PHP高可用后端]①②--图片上传到本地服务

[PHP高可用后端]①②--图片上传到本地服务

作者: 子木同 | 来源:发表于2017-11-02 17:11 被阅读13次
Paste_Image.png

Image.php

<?php
/**
 * Created by PhpStorm.
 * User: tong
 * Date: 2017/11/2
 * Time: 15:36
 */

namespace app\admin\controller;
use think\Request;

/**
 * 后台图片上传相关逻辑
 * Class Image
 * @package app\admin\controller
 */
class Image extends Base
{

    /**
     * 图片上传
     */
    public function upload()
    {
        //对应image.js 的fileObjName
        $file = Request::instance()->file('file');

        //halt($file);//array name type tmp_name error size

        //把文件上传到指定的文件夹
        $info = $file->move('upload');
        //halt($info);
        if ($info && $info->getPathname()) {
            $data = [
                'status' => 1,
                'message' => 'OK',
                'data' => '/' . $info->getPathname(),
            ];
            return json_encode($data);
        }
        return json_encode(['status' => 0, 'message' => '上传失败']);
    }
}
Paste_Image.png Paste_Image.png

相关文章

网友评论

      本文标题:[PHP高可用后端]①②--图片上传到本地服务

      本文链接:https://www.haomeiwen.com/subject/rxcapxtx.html