Jump to content

Wrong


Recommended Posts

What am I doing wrong here

$funnyurl = $site . $funnyurl;if (preg_match("/[.txt]{4}/i", $funnyurl)){require_once("./includes/view_text.php");}else if (preg_match("/[.jpg|.gif|.jpeg|.bmp|.tiff]{4}/i",$funnyurl)) {require_once("./includes/view_picture.php");}else if (preg_match("/[.mov]{4}/i",$funnyurl)) {require_once("./includes/view_quicktime.php");}else if (preg_match("/[.ram|.rm|.ra|.rpm]{4}/i",$funnyurl)) {require_once("./includes/view_realmedia.php");}else if (preg_match("/[.asf|.wma|.wmv|.wma|.wm|.asf|.avi|.mpeg|.mpg|.mp2|.mp3|.mid|.midi|.wav]{4}/i",$funnyurl)) {require_once("./includes/view_windowsmedia.php");}else if (preg_match("/[.swf|.swc|flv]{4}/i",$funnyurl)) {require_once("./includes/view_flash.php");}else {echo "No file exists at this location";}

http://www.funnyemailforwards.com/display.phpThe problem is currently, it shows a media player file it shouldn't were did I misformat my code?

Link to comment
Share on other sites

I found some issues and fixed them but it's still having the same problem any advice

<?php$funnyurl = $site . $funnyurl;if (preg_match("/[.txt]{4}/i", $funnyurl)){require_once("./includes/view_text.php");}elseif (preg_match("/[.jpg|.gif|.jpeg|.bmp|.tiff]{4}/i",$funnyurl)) {require_once("./includes/view_picture.php");}elseif (preg_match("/[.mov]{4}/i",$funnyurl)) {require_once("./includes/view_quicktime.php");}elseif (preg_match("/[.ram|.rm|.ra|.rpm]{4}/i",$funnyurl)) {require_once("./includes/view_realmedia.php");}elseif (preg_match("/[.asf|.wma|.wmv|.wma|.wm|.asf|.avi|.mpeg|.mpg|.mp2|.mp3|.mid|.midi|.wav]{4}/i",$funnyurl)) {require_once("./includes/view_windowsmedia.php");}elseif (preg_match("/[.swf|.swc|.flv]{4}/i",$funnyurl)) {require_once("./includes/view_flash.php");}else {echo "No file exists at this location";}?>

Link to comment
Share on other sites

I believe the problem is the {4} after each pattern, which tells it to match exactly 4 characters. .tiff and .ra do not have 4 characters, neither do .mpeg or .midi. If you want to use regular expressions, remove the {4} and replace it with a dollar sign to anchor the pattern to the end of the string.(preg_match("/[.mov]$/i",$funnyurl))Or you can just parse out the extension yourself, and use a switch statement:

$chunks = explode(".", $funnyurl);$ext = $chunks[count($chunks) - 1];switch ($ext){  case 'txt':    require_once("./includes/view_text.php");    break;  case 'jpg':  case 'gif':  case 'jpeg':  case 'bmp':  case 'tiff':    require_once("./includes/view_picture.php");    break;...  default:    echo "No file exists at this location";    break;}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...