hi guys, i want to include the icon of the type of file am uploading, is that possible????

Recommended Answers

All 3 Replies

Member Avatar for diafol

Yes. You need to create loads of icons for each type of file and a blank one for all filetypes not covered. There are loads of free icons out there you can get hold of and chage to your requirements. Be careful - some require a licence or forbid you to use them on a public site.

You can apply the icon to the file via php and css.

1) Copy the file extension from the filename.
2) Paste the extension into a classname for the <li> or whatever you're using to show the filename.
3) Use CSS to indent the text and show a particular image. If the whole thing is made into a download link, you could even create a rollover sprite for the icon, but that's another thing.

$xpos = strpos($filename,'.'); //you'll need to check that this isn't 0
$xpos = $xpos + 1; //this shifts the position along one place
$xt = substr($filename,$xpos); //this reads the extension for the specified position

echo "<li class=\"ext {$xt}\">{$filename}</li>";  //your html output

the css is easy:

.ext{
   text-indent: 20px;
}

.js{
  background: url(/myimages/js.gif) no-repeat;
}
.doc{
  background: url(/myimages/doc.gif) no-repeat;
}
.xls{
  background: url(/myimages/xls.gif) no-repeat;
}

etc. etc.

ah thanks sir, so meaning i should one by one filter the file being uploaded then classify it to what type of file is it? thanks sir..

Member Avatar for diafol

You should ALWAYS filter uploads. You won't be able to use my solution unless the file is actually uploaded to a specified folder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.