All the files in a certain directory are scanned using scandir()
for example. How then do I go through the files in that directory and create a small image (thumbnail) or whatever so that I can display that next to the name.
I will probably check the files one by one, and lets say it is another directory, the image will be default folder image. For PDF's maybe also. But then for video's and images and anything else like it, the image should be like a preview.
<?php
$data = array();
$files = array();
$allFiles = scandir($_REQUEST['dir_name']);
$files = array_diff($allFiles, array('.', '..'));
foreach($files as $key=>$file){
$data[$key]['name'] = $file;
if(is_dir(_REQUEST['dir_name'].'/'.$file)){
//Get small image of folder here and store that in $data[$key]['preview']
$data[$key]['type'] = 'dir';
}
else{
$extension = substr(strrchr($filename, "."));
$data[$key]['type'] = $extension;
switch ()$extension) {
case 'jpeg' : {
//Get small thumbnail of jpeg image here and store that in $data[$key]['preview'];
}
case 'png' : {
//Get small thumbnail of png image here and store that in $data[$key]['preview'];
}
case 'pdf' : {
//Get small thumbnail of pdf here and store that in $data[$key]['preview'];
}
case 'rar' : {
//Get small thumbnail of default .rar image here and store that in $data[$key]['preview'];
}
}
}
}
echo json_encode($data);
?>
I am prepared to do quite a few extensions, and maybe find a default later on for extensions not explicitly covered. I just need to know some of the different methods on generating a thumbnail from images, videos and documents as I suspect they are completely different.