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 ??? ???

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.