nginx指定路径,生成图片

nginx下的图片路径,外网访问不到,不在项目内,可用以下方法实现:

 

ImgConverToData.php

imgSrc = $source;
    }

    public function img2Data()
    {
        $this->_imgMime($this->imgSrc);

        return $this->imgData = fread(fopen($this->imgSrc, 'rb'), filesize($this->imgSrc));
    }

    public function data2Img()
    {
        header("content-type:$this->imgMime");

        return $this->imgData;
    }

    public function _imgMime($imgSrc)
    {
        $info = getimagesize($imgSrc);

        return $this->imgMime = $info['mime'];
    }
}

实现方法为:

public function showIdCard(Request $request)
    {
       
        $imgConverToData = new ImgConverToData();
        $imgConverToData->getImgDir($path);
        $imgConverToData->img2Data();
        $imgData = $imgConverToData->data2Img();
        echo $imgData;
        exit;
    }

 

你可能感兴趣的:(Linux,symfony,php)