CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> Tips & Solutions

 File extention 2 icon [PHP]

Print topic Send  topic

Author Message
feha


Posts: 712
Posted: 12/10/2005, 1:46 AM

  
//====================================================  
function file_icon($file_name)  
{     
//by www.vision.to  
  
	$ext=strrchr($file_name, ".");//Get file extention  
	switch(strtolower($ext))  
	{  
	   //assign particular icon  
	   //you can expand this as you need it ...  
		case ".pdf": $file_icon = "pdf.gif"; break;  
		case ".gif": $file_icon = "image.gif"; break;  
		case ".jpg": $file_icon = "image.gif"; break;  
		case ".png": $file_icon = "image.gif"; break;  
		case ".zip": $file_icon = "zip.gif"; break;  
		case ".txt": $file_icon = "txt.gif"; break;  
		case ".php": $file_icon = "script.gif"; break;  
		case ".htm": $file_icon = "htm.gif"; break;  
		case ".html": $file_icon = "html.gif"; break;  
		case ".xml": $file_icon = "xml.gif"; break;  
		case ".xsl": $file_icon = "xsl.gif"; break;  
		case ".xls": $file_icon = "xls.gif"; break;  
		case ".doc": $file_icon = "doc.gif"; break;  
		case ".csv": $file_icon = "csv.gif"; break;  
		case ".asp": $file_icon = "script.gif"; break;  
		case ".js": $file_icon = "js.gif"; break;  
		case ".mp3": $file_icon = "mp3.gif"; break;  
		case ".waw": $file_icon = "waw.gif"; break;  
		case ".cgi": $file_icon = "script.gif"; break;  
		case ".swi": $file_icon = "swi.gif"; break;  
		case ".swf": $file_icon = "swf.gif"; break;  
		case ".mov": $file_icon = "movie.gif"; break;  
		case ".qt": $file_icon = "movie.gif"; break;  
		case ".mpg": $file_icon = "movie.gif"; break;  
		case ".mpeg": $file_icon = "movie.gif"; break;  
		case ".sql": $file_icon = "database.gif"; break;  
		default: $file_icon = "fileicon.gif";  
  
	}  
	return $file_icon;  
}  
//====================================================  

This is a function to assign icons depending on file extensions.
You can use it in BeforeShow Event ...

enjoy

_________________
Regards
feha

www.vision.to
feedpixel.com
View profile  Send private message
DonB
Posted: 12/10/2005, 7:40 AM

A more compact solution (and it also works when the filename is like
'foo.bar.jpg'):

function file_icon($file_name) {

$ext = array_pop(explode(".", $file_name)); # Get tail-end of the filename

if (strpos("|pdf|zip|txt|htm|html|xml|xsl|doc|csv|mp3|waw|swi|swf", $ext))
$file = $ext;
else if (strpos("|gif|jpg|png", $ext)) $file = "image";
else if (strpos("|php|cgi|asp", $ext)) $file = "script";
else if (strpos("|qt|mpg|mpeg", $ext)) $file = "movie";
else if (strpos("|sql" , $ext)) $file = "database";
else $file = "fileicon";

return "$file.gif";

}


--
DonB

http://www.gotodon.com/ccbth


"feha" <feha@forum.codecharge> wrote in message
news:25439aa3ff03cbe@news.codecharge.com...
>
  
> //====================================================  
> function file_icon($file_name)  
> {  
> //by www.vision.to  
>  
> $ext=strrchr($file_name, ".");//Get file extention  
> switch(strtolower($ext))  
> {  
>    //assign particular icon  
>    //you can expand this as you need it ...  
> case ".pdf": $file_icon = "pdf.gif"; break;  
> case ".gif": $file_icon = "image.gif"; break;  
> case ".jpg": $file_icon = "image.gif"; break;  
> case ".png": $file_icon = "image.gif"; break;  
> case ".zip": $file_icon = "zip.gif"; break;  
> case ".txt": $file_icon = "txt.gif"; break;  
> case ".php": $file_icon = "script.gif"; break;  
> case ".htm": $file_icon = "htm.gif"; break;  
> case ".html": $file_icon = "html.gif"; break;  
> case ".xml": $file_icon = "xml.gif"; break;  
> case ".xsl": $file_icon = "xsl.gif"; break;  
> case ".xls": $file_icon = "xls.gif"; break;  
> case ".doc": $file_icon = "doc.gif"; break;  
> case ".csv": $file_icon = "csv.gif"; break;  
> case ".asp": $file_icon = "script.gif"; break;  
> case ".js": $file_icon = "js.gif"; break;  
> case ".mp3": $file_icon = "mp3.gif"; break;  
> case ".waw": $file_icon = "waw.gif"; break;  
> case ".cgi": $file_icon = "script.gif"; break;  
> case ".swi": $file_icon = "swi.gif"; break;  
> case ".swf": $file_icon = "swf.gif"; break;  
> case ".mov": $file_icon = "movie.gif"; break;  
> case ".qt": $file_icon = "movie.gif"; break;  
> case ".mpg": $file_icon = "movie.gif"; break;  
> case ".mpeg": $file_icon = "movie.gif"; break;  
> case ".sql": $file_icon = "database.gif"; break;  
> default: $file_icon = "fileicon.gif";  
>  
> }  
> return $file_icon;  
> }  
> //====================================================  
> 
>
> This is a function to assign icons depending on file extensions.
> You can use it in BeforeShow Event ...
>
> enjoy
>
> _________________
> Regards
> feha
> Vision.To Design
> www.vision.to
> wowdev.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.