Jump to content

PNG extension not recognized


digitex
 Share

Recommended Posts

Afternoon folks.

I'm having an issue I can't figure out. I have a file field that supports pdf doc and docx and png for uploads and I have the following code in the template:

$dls = $page->downloadable;
   	echo "<ul class=\"dl-list\">";
   	foreach($dls as $dl) {
		$fs = $dl->filesize;
		$tfs = (int)($fs / 1024);
		if($dl->ext() == "pdf") {
			$icon = "pdf";
		} else if($dl->ext() == "doc" or "docx") {
			$icon = "word";
		} else {
			$icon = "png";
		}
     echo "<li class=\"{$icon}\"><a href=\"{$dl->url}\" target=\"_blank\">{$dl->description}</a><span> | {$tfs}k</span></li>\n";
	}
 echo "</ul>";

I'm using CSS to give each extension type it's own icon and it recognizes pdf and doc/docx but the png is getting the Word icon rather than the png icon. Am I missing something obvious?

Any suggestions appreciated. Thanks.

Link to comment
Share on other sites

5 hours ago, digitex said:
} else if($dl->ext() == "doc" or "docx") {

You'll need to write this line as...

} else if($dl->ext() == "doc" or $dl->ext() == "docx") {

...or else it will always evaluate as true regardless of the extension.

A good candidate for rewriting as a switch statement too.

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

Haaaa! I did miss something obvious. Safe bet with me. I was under the impression I could short form that, not sure where I got that idea but it didn't throw an error so.....

Thanks Robin. If more file types are added to the list then a switch is absolutely what I'll use.

  • Like 1
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...