<?php
//scan "uploads" folder and display them accordingly
$scan = scandir('uploads');
foreach($scan as $file)
{
if (is_image("uploads/$file"))
{ ?>
<p><?php echo "this is an image"; ?></p>
<?php
}
if (is_pdf("uploads/$file"))
{ ?>
<p><?php echo "this is an PDF file"; ?></p>
<?php
}
if (is_html("uploads/$file"))
{ ?>
<p><?php echo "this is an HTML file"; ?></p>
<?php
}
}
?>
I want to display the file as file type. If the file is an image show this is an image, if the file is PDF show the file is PDF Please Help me with this code. Pls, Pls
You can do a simple str_pos()
/ substr()
to detect if the string contains a .pdf file extension or a .html or a .png/.jpg.
Here's some example code:
if (substr($filename, -4) == '.jpg') {
echo "Jpeg!";
}
Just make the other switches for the different file types and you're golden. Ideally, pass all the files to one function and have all the logic contained there.