使用file_get_content检索图像文件的困难

时间:2013-02-13 21:59:45

标签: php string file-get-contents image-uploading

我正在尝试获取图像路径并在tmp目录中打开相应的图像,但页面只显示一个空的img占位符pic。提前致谢

public function getImage($path)
    {
        if($result = $this->db->prepare("SELECT filename FROM trips WHERE filename=?"))
        {
            $result->bind_param('s', $path);
            $result->execute();
            $result->bind_result($filename);
            if($result->fetch())
            {

                    header("Content-type: image/jpeg");

                    if(!file_exists("C:/xampp/htdocs/webshop/public/img/content/" . $filename))
                    {
                         imagefilter($image, IMG_FILTER_GRAYSCALE);
                         imagejpeg($image, "C:/xampp/htdocs/webshop/public/img/content/" . $filename);
                    }
                    else
                    {
                        $image = imagecreatefromjpeg("C:/xampp/htdocs/webshop/public/img/content/" . $filename);
                    }

                        imagejpeg($image);
            }
            else
            {
                echo "error";
            }
        }
        else
        {
            echo "Table retrieve failed: (" . $this->db->error . ") " .$this->db->error;
        }
        var_dump($img);
        return $image;
    }

0 个答案:

没有答案