开发者

PHP temporary image and CodeIgniter view

开发者 https://www.devze.com 2023-02-16 21:23 出处:网络
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.

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

精彩评论

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