473,396 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Open Dir

[php]
<?php
echo "<form method=post>";
echo "<input type=text name=dirname>";
echo "<input type=submit value='Show file' name=knopka>";
echo "</form>";
$d=opendir($_REQUEST[dirname]);

while (($str=readdir($d)) != NULL ) {
if ( is_dir("$_REQUEST[dirname]".$str) ) {
echo "<img src=folder.bmp> $str";
}
echo "<br>";
}
closedir($d);
?>[/php]
Let's keep our posted code readable, PLEASE!!

i have such program and i asigned a folder icon for folders how i must assign one for JPG file special jpg icon (windows Default)
Nov 19 '06 #1
9 2979
ronverdonk
4,258 Expert 4TB
Are you looking for the code to assign icons to specific file types or just for the jpg icon?

Ronald :cool:
Nov 19 '06 #2
Are you looking for the code to assign icons to specific file types or just for the jpg icon?

Ronald :cool:
i want to assign JPG icon for JPG File ,Note pad Icon for txt file i have the icons i need to know how i must do it .
i have tried is_file but can't use it in correct way.
Nov 19 '06 #3
ronverdonk
4,258 Expert 4TB
Here is a sample that reads the files in a directory and shows them in a table, preceeded by an image, depending on the file extension.[php]<?php
$path = "mail/";
$dir = dir($path);
echo "<table border='0'>";
while ($file=$dir->read() ) {
if ($file != '.' && $file != '..') {
if (!$icon = fileExt($file)) {
$icon = "default.gif";
}
echo "<tr><td><img src='$icon' border='0'></td><td>$file</td></tr>";
}
}
echo '</table>';

function fileExt($fn) {
$f_ext = "";
$fn=strtolower($fn);
ereg( ".*\.([a-zA-z0-9]{0,5})$", $fn, $regs ); // extract file extension
$f_ext = $regs[1];
switch ($f_ext)
{
case "jpg" : return "jpg.gif"; break;
case "txt" : return "txt.gif"; break;
case "png" : return "png.png"; break;
case "php" : return "php.gif"; break;
// do the rest yourself
default : return "default.gif"; break;
}
return false;
}
?>[/php]
Ronald :cool:
Nov 19 '06 #4
How do you distinguish a folder?
Nov 20 '06 #5
Nevermind, I finally found it. I used @is_dir()

Multiple icons can be found here, note they are 16x16.
Zipped image files

Also here is the code for a full directory view with icons.
[PHP]
<?php
$path = "../";
$dir = dir($path);
echo "<table border='0'>";
while ($file=$dir->read() ) {
if ($file != '.' && $file != '..') {
$icon = fileExt($file, $path);
echo "<tr><td>$icon</td><td>$file</td></tr>\n";
}
}
echo '</table>';

function fileExt($file, $path)
//find the appropriate icon depending on the extension (returns a link to the image file)
{
ereg( ".*\.([a-zA-z0-9]{0,5})$", $file, $regs ); // extract file extension
$ext = $regs[1];
$icon_path='winxp';
if ($icon_path == '')
{
return '';
}
if ($ext == '')
{
$icon = 'generic';
if (@is_dir($path . $file))
{
$icon = 'dir';
}
}
else
{
$icon = 'unknown';
static $icon_types = array(
'binary' => array('bat', 'bin', 'com', 'dmg', 'dms', 'exe', 'msi',
'msp', 'pif', 'pyd', 'scr', 'so'),
'binhex' => array('hqx'),
'cd' => array('bwi', 'bws', 'bwt', 'ccd', 'cdi', 'cue', 'img',
'iso', 'mdf', 'mds', 'nrg', 'nri', 'sub', 'vcd'),
'comp' => array('cfg', 'conf', 'inf', 'ini', 'log', 'nfo', 'reg'),
'compressed' => array('7z', 'a', 'ace', 'ain', 'alz', 'amg', 'arc',
'ari', 'arj', 'bh', 'bz', 'bz2', 'cab', 'deb', 'dz', 'gz',
'io', 'ish', 'lha', 'lzh', 'lzs', 'lzw', 'lzx', 'msx', 'pak',
'rar', 'rpm', 'sar', 'sea', 'sit', 'taz', 'tbz', 'tbz2',
'tgz', 'tz', 'tzb', 'uc2', 'xxe', 'yz', 'z', 'zip', 'zoo'),
'dll' => array('386', 'db', 'dll', 'ocx', 'sdb', 'vxd'),
'doc' => array('abw', 'ans', 'chm', 'cwk', 'dif', 'doc', 'dot',
'mcw', 'msw', 'pdb', 'psw', 'rtf', 'rtx', 'sdw', 'stw', 'sxw',
'vor', 'wk4', 'wkb', 'wpd', 'wps', 'wpw', 'wri', 'wsd'),
'image' => array('adc', 'art', 'bmp', 'cgm', 'dib', 'gif', 'ico',
'ief', 'jfif', 'jif', 'jp2', 'jpc', 'jpe', 'jpeg', 'jpg', 'jpx',
'mng', 'pcx', 'png', 'psd', 'psp', 'swc', 'sxd', 'tga',
'tif', 'tiff', 'wmf', 'wpg', 'xcf', 'xif', 'yuv'),
'java' => array('class', 'jar', 'jav', 'java', 'jtk'),
'js' => array('ebs', 'js', 'jse', 'vbe', 'vbs', 'wsc', 'wsf',
'wsh'),
'key' => array('aex', 'asc', 'gpg', 'key', 'pgp', 'ppk'),
'mov' => array('amc', 'dv', 'm4v', 'mac', 'mov', 'mp4v', 'mpg4',
'pct', 'pic', 'pict', 'pnt', 'pntg', 'qpx', 'qt', 'qti',
'qtif', 'qtl', 'qtp', 'qts', 'qtx'),
'movie' => array('asf', 'asx', 'avi', 'div', 'divx', 'dvi', 'm1v',
'm2v', 'mkv', 'movie', 'mp2v', 'mpa', 'mpe', 'mpeg', 'mpg',
'mps', 'mpv', 'mpv2', 'ogm', 'ram', 'rmvb', 'rnx', 'rp', 'rv',
'vivo', 'vob', 'wmv', 'xvid'),
'pdf' => array('edn', 'fdf', 'pdf', 'pdp', 'pdx'),
'php' => array('inc', 'php', 'php3', 'php4', 'php5', 'phps',
'phtml'),
'ppt' => array('emf', 'pot', 'ppa', 'pps', 'ppt', 'sda', 'sdd',
'shw', 'sti', 'sxi'),
'ps' => array('ai', 'eps', 'ps'),
'sound' => array('aac', 'ac3', 'aif', 'aifc', 'aiff', 'ape', 'apl',
'au', 'ay', 'bonk', 'cda', 'cdda', 'cpc', 'fla', 'flac',
'gbs', 'gym', 'hes', 'iff', 'it', 'itz', 'kar', 'kss', 'la',
'lpac', 'lqt', 'm4a', 'm4p', 'mdz', 'mid', 'midi', 'mka',
'mo3', 'mod', 'mp+', 'mp1', 'mp2', 'mp3', 'mp4', 'mpc',
'mpga', 'mpm', 'mpp', 'nsf', 'oda', 'ofr', 'ogg', 'pac', 'pce',
'pcm', 'psf', 'psf2', 'ra', 'rm', 'rmi', 'rmjb', 'rmm', 'sb',
'shn', 'sid', 'snd', 'spc', 'spx', 'svx', 'tfm', 'tfmx',
'voc', 'vox', 'vqf', 'wav', 'wave', 'wma', 'wv', 'wvx', 'xa',
'xm', 'xmz'),
'tar' => array('gtar', 'tar'),
'text' => array('c', 'cc', 'cp', 'cpp', 'cxx', 'diff', 'h', 'hpp',
'hxx', 'm3u', 'md5', 'patch', 'pls', 'py', 'sfv', 'sh',
'txt'),
'uu' => array('uu', 'uud', 'uue'),
'web' => array('asa', 'asp', 'aspx', 'cfm', 'cgi', 'css', 'dhtml',
'dtd', 'grxml', 'htc', 'htm', 'html', 'htt', 'htx', 'jsp', 'lnk',
'mathml', 'mht', 'mhtml', 'perl', 'pl', 'plg', 'rss', 'shtm',
'shtml', 'stm', 'swf', 'tpl', 'wbxml', 'xht', 'xhtml', 'xml',
'xsl', 'xslt', 'xul'),
'xls' => array('csv', 'dbf', 'prn', 'pxl', 'sdc', 'slk', 'stc', 'sxc',
'xla', 'xlb', 'xlc', 'xld', 'xlr', 'xls', 'xlt', 'xlw'));
foreach ($icon_types as $png_name => $exts)
{
if (in_array($ext, $exts))
{
$icon = $png_name;
break;
}
}
}
return "<img alt=\"[$ext]\" height=\"16\" width=\"16\" src=\"$icon_path/$icon.png\" /> ";
}
?>
[/PHP]
Nov 20 '06 #6
ronverdonk
4,258 Expert 4TB
themadmidget: Nice piece of code you showed us. Any chance you could show me a path to the larger 32x32 icons??

Ronald :cool:
Nov 21 '06 #7
I don't have any but you can get your own from your computer with this.
For Windows XP users, may I suggest you look (with the above software) at C:\Windows\System32\shell32.dll and C:\Windows\System32\shimgvw.dll
Most system icons are located in .dll files if you are looking for specific icons such as for PDF files, look at the .exe files that reads them ex. C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe
Nov 21 '06 #8
ronverdonk
4,258 Expert 4TB
Thanks for the tip!

Ronald :cool:
Nov 21 '06 #9
Thanks for the tip!

Ronald :cool:
i get my icons from dll files by icon extractor programs .
also thanks for codes my friends they help me very much
Nov 21 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
10
by: David McCulloch | last post by:
The following code opens a new window, but the "resizeTo" doesn't resize it. Why not? (Don't ask why I simply did not open the window with the new size....my original problem was how to open a...
3
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
7
by: anthony.turcotte | last post by:
Hi, I've looked for a solution to this problem on google, read posts in this newsgroup and I still haven't found anything that could help me. Here's the scenario. 1. User accesses...
19
by: =?Utf-8?B?R3JlZw==?= | last post by:
How can I tell via code if a Form is already open. Each time my forms load I have some initialization code that runs, but if the form is already open and hidden I don't want that initialization...
0
by: Salad | last post by:
A97. Split database. Frontend DB1.MDB. Backend DB1BE.MDB. Tables are linked between DB1 and DB2. From my testing, if I open DB1 exclusively using /excl the backend DB1BE is not opened...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.