Jump to content

Getting file type from a string into anchor


themeatpuppet

Recommended Posts

I'm pulling out links from a database, some of them are images, some are movies, some are URLs and some are just download files. I need a way to differentiate each of the to be printed in the anchor tag this is what I'm doing:

 

for($j=0;$j<count($links);$j++) {
        // explode on '.' to separate string
$link_path = explode('.',$links['link_path']);
        // get last element for extension
$link_path=$link_path[count($link_path)-1];
					if($link_path=='jpg'|| 
$link_path=='gif'||
$link_path=='png'||
$link_path=='JPG'||
$link_path=='jpeg'||
$link_path=='JPEG'||
$link_path=='GIF'||
$link_path=='PNG'||
$link_path=='swf'||
$link_path=='SWF') {
$link_image = getimagesize($folder.'/'.links['link_path']);
$link_location = $folder.'/';
$link_target = "\" onclick=\"popUp(this.href,'console',$link_image[1],$link_image[0]);return false;\" target=\"newWin\">";
					} elseif($link_path=='cfm'||$link_path='htm'||$link_path='html') {
						$link_location = $folder.'/';
						$link_target = '">';
				 	} else {
						$link_location='';
						$link_target = '">';
					}
				$links_div .='<li><a href="'.$link_location.$links['link_path'].$link_target.$links['link_name'].'</a>';
					if(($i!=count($links))||$i==0) {
						$links_div .= " | </li>";
					} else {
						$links_div .= "</li>";
					}
			}

 

Well the idea makes sense to me, but for some reason i don't understand, the loop is skipping the last else statement and those links that should be processed as such end up as the second elseif. It's like a riddle ??? ???

Simple typo. Change this line:

} elseif($link_path=='cfm'||$link_path='htm'||$link_path='html') {

to

} elseif($link_path=='cfm'||$link_path=='htm'||$link_path=='html') {

 

You were using a single equals sign, which is the assignment operator. It will always evaluate to true, so that elseif would never fail.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.