How to get thumbnail file name?
Added by Onyx Chalcedony 7 months ago
If I am accessing the thumbnail directory from another PHP script, what is the method I would use to get the correct thumbnail for a given image?
I see they are md5 hashed, but couldn't work out why the elfinder class returned a shorter filename than the corresponding md5('full/path/to/file.jpg').
For instance on one file, the md 5 sum of
a53831bb0fd5e274e0b650aa45d6c1c91318215940
is returned by md5('full/path/to/file.jpg'), but the actual thumbnail is called
a53831bb0fd5e274e0b650aa45d6c1c9.png
a difference of 10 characters.
Replies (5)
RE: How to get thumbnail file name?
-
Added by Troex Nevelin 7 months ago
md5 must always be 32 characters long! The suffix of 10 last numbers in your case looks like unix timestamp, check your script it adds timestamp somewhere
RE: How to get thumbnail file name?
-
Added by Onyx Chalcedony 7 months ago
Troex Nevelin wrote:
md5 must always be 32 characters long! The suffix of 10 last numbers in your case looks like unix timestamp, check your script it adds timestamp somewhere
Wow, didn't see that in there...but you are right!
RE: How to get thumbnail file name?
-
Added by Onyx Chalcedony 7 months ago
Ok, what I am trying to do is get a frontend php/jquery app to display a thumbnail loaded after the user has used elfinder to select the image, dynamically.
So <input type="text" name="image1" id="image1"> now has a value of for example "http://localhost/Quartzdemo/images/test/1312124274_cabinet.png". The image is there , but it's real name is /var/www/Quartzdemo/images/test/1312124274_cabinet.png, which is what the md5 is made of, and therefore the thumbnail.
Do I need to build another php script to strip the filename down, rebuild it to real filename, and grab the thumbnail accordingly? Or is there a method I can use in elfinder to return the real filename instead of the url?
RE: How to get thumbnail file name?
-
Added by Troex Nevelin 7 months ago
Probably another script, elFinder will return path or URL, but not the filename
RE: How to get thumbnail file name?
-
Added by Onyx Chalcedony 7 months ago
Thanks. For the benefit of anyone else trying to do this, this is the script I built ; meant to be used by a Jquery ajax method to retrieve the thumbnails for dynamic loading.
<?php
//custom handler to retrieve thumbs for elfinder 1.x
//sanity checks first
$name = $_GET['name'] ? $_GET['name'] : $_POST['name']; //name of file - browser address of file eg http://localhost/mysite/images/test/me/me.jpg
$dir = $_GET['dir'] ? $_GET['dir'] : $_POST['dir']; // name of dir to begin search - pass the main location of the image files - filesystem NOT browser eg /var/www/mysite/images
$httprefix =$_GET['httprefix'] ? $_GET['httprefix'] : $_POST['httprefix']; //httprefix of thumb file - the browser address eg http://localhost/mysite/images/
if ($dir =='' || $name =='' || !is_dir($dir)) return false;
$shortname = array_pop(explode('/',$name)); //get the file's name, not path
$firstpath = $dir; // the location of the first dir, to stay static
$result = (searchTree($dir, $shortname)); // do the work
function searchTree($path,$shortname) {
global $firstpath;
global $httprefix;
global $name;
$delim='/';
$array= Array();
if ($sdir=@opendir($path)) {
while (($element=readdir($sdir))!== false) {
if ('.' == substr($element, 0, 1) ) continue; //skip hidden dirs
if (is_dir($path.$delim.$element)) {
$array[$element] = searchTree($path.$delim.$element, $shortname);
} else{
$array[] = $path.$delim.$element;
if ($shortname == $element) {
$thumbfile = $firstpath.$delim.'.tmb'.$delim.md5($path.$delim.$shortname).'.png';
$filename01 = $path.$delim.$shortname;
$filename02 = $name;
if (file_exists($thumbfile) && (md5(file_get_contents($filename01)) == md5(file_get_contents($filename02)))){
print $httprefix.'.tmb'.$delim.md5($path.$delim.$shortname).'.png';
// this will only be one file so use the print here to get it out immediately
}
}
}
}
closedir($sdir);
}
}
?>
If you want the form outlined too then drop me a line; onyx at chalcedony dot co dot nz.
(1-5/5)