Project / Support Center
Welcome, Guest. Please login or register. July 04, 2022, 01:40: PM
Home Help Search Login Register
D-Web Web Site Creator D - Web Web Site Creator On-line HTML Editor No Programming knowledge required. Web Global Net PayPal-Cart Shopping Cart System PayPal - Kart Shopping Cart System for E-Commerce over the internet, that's easy to use. Web Global Net Newsletter Manager Newsletter Manager On-line Newsletter Creator with Email Subscriber Management.
Ring Central Discount
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  MySQL/PHP  |  Topic: getting a files extention down and dirty 0 Members and 2 Guests are viewing this topic. « previous next »
Pages: [1] Go Down Send this topic Print
Author Topic: getting a files extention down and dirty  (Read 8618 times)
admin
Guest
« on: July 08, 2009, 09:03: PM »

if you're storing a uploaded files name on a mysql table field the easiest way to get the file extention is to use a variable to pull it out. the variable can then be used if need for a  show if display;

we had a job where the client wanted to be able to upload images and display them and one of the image or file formats they wanted to use was swf - displaying swf files required embedding the file so it would work. doing this dynamically was not an issue where the issue came up was when they upload other files formats such as jpeg or gif as they require different image related display properties.

so we had to use a show if based on the file extention in other words if the file was a jpeg or gif show it but if it was a swf file then only show that.

what we ended up doing was creating a variable like this:

the file name was header.swf

to pull out the swf we did this

<?php
$file=substr($row_rssettings['header'],-3);
?>


Explanation :
substr Return part of a string
[   string substr  ( string $string  , int $start  [, int $length  ] )  ]

Example Using a negative start
<?php
$rest = substr("abcdef", -1);    // returns "f"
$rest = substr("abcdef", -2);    // returns "ef"
$rest = substr("abcdef", -3, 1); // returns "d"
?>



This variable $file grabs the last 3 characters in the file name - in our case swf

in order to use it in a show if function this is how we did it

  <?php
// Show IF Conditional region
if ($file == "swf") {
?>
                              <embed src="<?php echo $row_rssettings['site_home_page_address']; ?>/admin/prod_images/settings/web/<?php echo $row_rssettings['header']; ?>" width="100%" ></embed>
                              <?php
// else Conditional region
} else { ?>
                          <img src="<?php echo $row_rssettings['site_home_page_address']; ?>/admin/prod_images/settings/web/<?php echo $row_rssettings['header']; ?>"  alt="" align="left" />   
     <?php }
// endif Conditional region
?>

this works fine if you're only allows swf and no other type of files that need to be embedded.
« Last Edit: July 08, 2009, 09:08: PM by Web Global Net » Report to moderator   Logged
Pages: [1] Go Up Send this topic Print 
Web Global Net Web Application & Web Development Project Center  |  Technical Issues  |  MySQL/PHP  |  Topic: getting a files extention down and dirty « previous next »
Jump to:  


Login with username, password and session length
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!