php - I want to display file list using file type -


<?php         //scan "uploads" folder , display them accordingly        $scan = scandir('uploads');              foreach($scan $file)             {                if (is_image("uploads/$file"))                 { ?>                     <p><?php echo "this image"; ?></p>             <?php                         }               if (is_pdf("uploads/$file"))                 { ?>                     <p><?php echo "this pdf file"; ?></p>             <?php                         }               if (is_html("uploads/$file"))                 { ?>                     <p><?php echo "this html file"; ?></p>             <?php                         }               }        ?> 

i want display file file type. if file image show image, if file pdf show file pdf please me code. pls, pls

you can simple str_pos() / substr() detect if string contains .pdf file extension or .html or .png/.jpg.

here's example code:

if (substr($filename, -4) == '.jpg') {        echo "jpeg!"; } 

just make other switches different file types , you're golden. ideally, pass files 1 function , have logic contained there.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -