Sarang
Sarang

Reputation: 784

How to check if the file is flash or image file in PHP?

I need to check if the file which exist is the flash file or the image file, so i can put the file in Object tag or img tag respectively.

Upvotes: 0

Views: 244

Answers (3)

Ajesh VC
Ajesh VC

Reputation: 635

You can use this code to get extensions of files from its file name. And can check this file is image or flash using Conditional statement IF as below

<?php
$filename ="file.jpg";

$ext = strtolower(array_pop(explode('.',$filename)));
    if ($ext=='swf'){
    echo "flash";//set your object as flash
    }
    else{
    echo "image";//set your object as img
    }
    ?>

Upvotes: 1

GTS Soft.
GTS Soft.

Reputation: 177

You can simply use $_FILES['file_name']['type']; and it will return you file type that you can check alternatively you can use

list($width, $height, $type, $attr) = getimagesize("profilepic/".$db_question_data[$lpcntrl]['Photo']);

it will also return you file type of tile in $type variable. Hope this help :)

Upvotes: 1

prava
prava

Reputation: 3986

You can use pathinfo for this like below:

<?php
$path_parts = pathinfo($filepath);

echo $path_parts['extension']; // You can get the file extension for this
?> 

Upvotes: 0

Related Questions