PHP show thumbnail depending on file type -


all files in directory scanned using scandir() example. how go through files in directory , create small image (thumbnail) or whatever can display next name.

i check files 1 one, , lets directory, image default folder image. pdf's maybe also. video's , images , else it, image should preview.

<?php $data = array(); $files = array();  $allfiles = scandir($_request['dir_name']); $files = array_diff($allfiles, array('.', '..')); foreach($files $key=>$file){     $data[$key]['name'] = $file;     if(is_dir(_request['dir_name'].'/'.$file)){     //get small image of folder here , store 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 , store in $data[$key]['preview'];          }         case 'png' : {             //get small thumbnail of png image here , store in $data[$key]['preview'];          }         case 'pdf' : {             //get small thumbnail of pdf here , store in $data[$key]['preview'];          }         case 'rar' : {             //get small thumbnail of default .rar image here , store in $data[$key]['preview'];          }         }     } } echo json_encode($data); ?> 

i prepared quite few extensions, , maybe find default later on extensions not explicitly covered. need know of different methods on generating thumbnail images, videos , documents suspect different.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -