Reputation: 584
I have an animated GIF image in a folder not accessible by the web. I would like to output that image through PHP GD, but when outputted, the GIF is unanimated.
Any help?
Upvotes: 1
Views: 1134
Reputation: 42935
You use a 'routing script' to access such images (or whatever types of files):
client->routing script->open file and forward content->client
The client requests an url like this: http://your.domain/some/path/image.php?id=animation
Use something like this to output the files content to the client:
<?php
// some catalog (or database) where file-paths are kept
$catalog = array(
'animation' => '/path/to/animated_gif.gif';
);
// read which file the client wants to access
$id = $_GET['animation'];
// decide action on where that file is located physically
if (!isset($catalog['id'])
{
// die with error message
die('forbidden');
}
// send file content
$success = readfile($catalog['id']);
if (FALSE === $success)
{
// die with error message
die('sorry, problems to give the file.');
}
Note that for this to work the gif file does not ahve to be accessible directly via the http server. It is the local script that accesses the file based inside the local file system. So the script acts as a router for the clients request.
Inside the script to can do all sorts of fancy things:
Upvotes: 0
Reputation: 21
Instead of processing the image all over again in PHP-GD (you will be allocating far more resources that way instead of just reading a file that already exists.
Return the file data to the client
if (!is_readable($FILE)){
exit('Undefined file');
}
header('Content-type: image/gif');
echo file_get_contents($FILE);
Upvotes: 1