开发者

PHP temporary image and CodeIgniter view

I have .jpg images in path (/home/folder1/folder2/) to deny public access to the images. I'm using CodeIgniter and following function to show single image.

function show_image()
{
    $imag开发者_Python百科e_path = '/home/folder1/folder2/photo2.jpg';
    $image = file_get_contents($image_path);
    header("Content-Type: image/png");
    echo $image;
}

I would like to have solution where I can pass the resized image to CodeIgniter view and show it using tag.

function show_image2()
{
 // TODO image load and resize

 // loaded and resized image
 $data['image'] = $image;
 $this->load->view('show_image', $data);
}

View:

<img src="<?php echo $image; ?>" />

Do I need to make temporary copy of image to public path?

EDIT: How can I make temporary copy of image? Source folder is "/home/folder1/folder2" and destination folder is "example.com/images". Image should be deleted when user changes the image.


Yes you do, unless you're passing the function the raw image data (which means you'll need to change show_image() a bit :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜