简体   繁体   中英

Display animated GIF from outside public directory (GD?)

Once users upload their images to a non public (ie outside htdocs or public_html folder) folder, I use GD to fetch the image from that folder. This is all in the name of security, as the images themselves are never displayed without being processed.

The issue lies in animated GIFs, which GD is only capable of displaying by showing only it's first frame.

I know that there are classes out there that can slice the gifs up into their respective frames and "glue" them back together, but I'm looking to display these on the fly...

I don't want to create a new animated gif and show that, but rather have a GD script that renders the image from the information it gets from the photo directory, located outside of the public folder.

Thanks so much!

If you're not manipulating the image at all, I would just return the contents of the file with the correct header.

For example:

<?php 

$file = 'whatever.gif';

// Do whatever checks you want on permissions etc

header('Content-type: image/gif');
readfile($file);

?>

Readfile outputs the contents of the file, and the header makes sure the browser sees it as a gif and shows it. Because you're not using GD it will still be animated.

The catch with this method is you'll need to know the content type for each file to server it correctly.

http://php.net/manual/en/function.readfile.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM