Jump to content

Indexer Extension Icons, Help Needed


Ziegel
 Share

Recommended Posts

Hi there,Note: I did a lot of research on forums websites to fix the problem but didnt find any help.Iam still learning PHP i always used HTML with CSS but never builded PHP scripts from zero.Anyways, A friend helped me a while ago with a directory indexer but he turned images to BASE64 code.On that time he told me base64 is nice so they wont capture your images. But today I dont care and have my own nice made icons.Maybe hard to explain for me because the technical english :)Here are some parts of the script where the problem may sits.Example:

$img['img'] = ""; between the quotes standed base64 image code. But what I want now is just _img/icons/iconname.png
<?phperror_reporting(E_ALL); if(IsSet($_GET['i'])){ $i = trim($_GET['i']); $img['img'] = ""; $img['htm'] = ""; $img['zip'] = ""; $img['dir'] = ""; $img['<x>'] = ""; $img['rar'] = &$img['zip']; $img['tar'] = &$img['zip']; $img['html'] = &$img['htm']; $img['php'] = &$img['htm']; $img['asp'] = &$img['htm']; $img['jpg'] = &$img['img']; $img['gif'] = &$img['img']; $img['png'] = &$img['img']; $img['bmp'] = &$img['img']; if(IsSet($img[$i])) { $d = &$img[$i]; } else { $d = &$img['<x>']; } header('Content-type: image/png'); header('Content-Disposition: attachment; filename="' . $i . '"'); exit;}
Here is the HTML part:
<?phpif(IsSet($show)){ $i = 0; foreach($show as $row) { $tr_class = ($i % 2 ? 'row1' : 'row2');?> <tr class="<?php echo $tr_class; ?>"> <td><img src="_img/<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>"alt="<?php echo $row; ?>"></td> <td><a href="<?php echo (is_dir($dir . $row) ? 'index.php?dir=' . $dir . $row : $dir . $row); ?>"><?php echo $row; ?></a></td> <td align="left"><?php echo size(is_dir($dir . $row) ? dsize($dir . $row . '/') : fsize($dir . $row)); ?></td> <td><?php echo (is_dir($dir . $row) ? 'File Folder' : getExt($row) . ' File'); ?></td> <td><?php echo date('F d Y H:i:s', filectime($dir . $row)); ?></td> </tr><?php
I replaced:
<img src="index.php?i=<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>" alt="<?php echo $row; ?>">
With:
<img src="_img/<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>"alt="<?php echo $row; ?>">
To make a work-around, It works and it links to the icon folder but does not add .png behind it. just the file name.Screenshot:showmc.jpgAnd another question:The indexer shows the index.php file and a folder, These needs to be hidden. How can I hide that index.php and that folder in the PHP file? Edited by Ziegel
Link to comment
Share on other sites

You can use file_get_contents to get the data from each file:

$img['img'] = file_get_contents('images/img.png');

How can I hide that index.php and that folder in the PHP file?
You can check for that in the code which prints everything. I assume that's probably in $show or $row. It would probably be useful to print $row out to see what it is, but you could probably compare that with a list of things you don't want to show. You can also use is_dir to check if a path is a directory.
Link to comment
Share on other sites

I think he try's to get the images because all icons become the same size.But i think he wont read the .png extension.Here is the whole script.

<?phperror_reporting(E_ALL);if(IsSet($_GET['i'])){		$i = trim($_GET['i']);		$img['img'] = file_get_contents('_img/image.png');		$img['htm'] = file_get_contents('_img/project.png');		$img['zip'] = file_get_contents('_img/package.png');		$img['dir'] = file_get_contents('_img/folder.png');		$img['<x>'] = file_get_contents('_img/folder.png');		$img['rar'] = &$img['zip'];		$img['tar'] = &$img['zip'];		$img['html'] = &$img['htm'];		$img['php'] = &$img['htm'];		$img['asp'] = &$img['htm'];		$img['jpg'] = &$img['img'];		$img['gif'] = &$img['img'];		$img['png'] = &$img['img'];		$img['bmp'] = &$img['img'];		if(IsSet($img[$i]))		{				$d = &$img[$i];		}		else		{				$d = &$img['<x>'];		}		header('Content-type: image/png');		header('Content-Disposition: attachment; filename="' . $i . '"');		exit;}function getExt($filename){		$atemp = explode('.', $filename);		return strtolower($atemp[sizeof($atemp) - 1]);}function size($size){		$mult = 'KB';		$prec = 0;		if(round($size / 1024, 0))		{				$size /= 1024;				$mult = 'KB';				$prec = 3;		}		if(round($size / 1024, 0))		{				$size /= 1024;				$mult = 'MB';				$prec = 3;		}		return (round($size, $prec) . ' ' . $mult);}function fsize($sfile){		return filesize($sfile);}function dsize($sdir){		$size = 0;		$handle = opendir($sdir);		while(false !== ($read = readdir($handle)))		{				if($read <> '.' && $read <> '..')				{						if(is_file($sdir . $read))						{								$size += fsize($sdir . $read);						}						elseif(is_dir($sdir . $read))						{								$size += dsize($sdir . $read . '/');						}				}		}		return $size;}if(IsSet($_GET['dir']) && $_GET['dir'] <> '' && is_dir($_GET['dir'])){		if($_GET['dir'] == './')		{				$dir = $_GET['dir'];		}		elseif(eregi('\.\./', $_GET['dir']))		{				$dir = './';		}		else		{				if(substr($_GET['dir'], -1) == '/')				{						$dir = $_GET['dir'];				}				else				{						$dir = $_GET['dir'] . '/';				}		}} else {		$dir = './';}if($dir == './'){		$cur_dir = 'Folder';}else{		$ex = explode('/', $dir);		array_pop($ex);		$cur_dir = ucwords(array_pop($ex));}$handle = opendir($dir);while(false !== ($read = readdir($handle))){		if($read <> '.' && $read <> '..')		{				$show[] = $read;		}}?><html><head>		<title>Renovatio</title>		<style>		body { margin: 0px; }		body, td, th { font-family: Arial; font-size: 12px; }		a { color: #000000; text-decoration: none; }		a:hover { color: #666666; text-decoration: none; }		.dir_container {width: 1000px; }		.dir_container h1 { margin: 10px; }		.dir_container th { background-color: #000000; color: #FFFFFF; text-align: left; }		.row1 { background-color: #FFFFFF; }		.row2 { background-color: #DDDDDD; }		.error { background-color: #F2DDDD; border: 1px solid #992A2A; border-top: 0px; font-family: Verdana; margin: 5px; padding: 0px; }		.error h4 { background-color: #E3C0C0; border: 1px solid #992A2A; border-left: 0px; border-right: 0px; font-family: Verdana; color: #992A2A; font-size: 12px; font-weight: bold; margin: 0px; padding: 5px; }		.error p { background-color: transparent; border: 0px; font-family: Verdana; color: #992A2A; font-size: 12px; margin: 0px; padding: 8px; }		</style></head><body>		<div align="center">				<table border="0" cellpadding="5" cellspacing="0" class="dir_container">						<tr>								<td colspan="5">										<h1>										  <?phpif($dir <> './'){		$ex = substr($dir, 2, -1);		$ex = explode('/', $ex);		array_pop($ex);		$dirs = '<a href="index.php?dir=./">Folder</a> / ';		foreach($ex as $nr => $tdir)		{				$link = './';				for($i = 0; $i < $nr; $i++)				{						$link .= $ex[$i] . '/';				}				$dirs .= '<a href="index.php?dir=' . $link . $tdir . '">' . $tdir . '</a> / ';		}		echo $dirs;}?>										<?php echo $cur_dir; ?></h1></td>						</tr>						<tr>								<th width="1%"></th>								<th>Name:</th>								<th width="15%">Size:</th>								<th width="20%">Type:</th>								<th width="30%">Modified On:</th>						</tr><?phpif(IsSet($show)){		$i = 0;		foreach($show as $row)		{				$tr_class = ($i % 2 ? 'row1' : 'row2');?>						<tr class="<?php echo $tr_class; ?>">								<td><img src="_img/<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>" alt="<?php echo $row; ?>"></td>								<td><a href="<?php echo (is_dir($dir . $row) ? 'index.php?dir=' . $dir . $row : $dir . $row); ?>"><?php echo $row; ?></a></td>								<td align="right"><?php echo size(is_dir($dir . $row) ? dsize($dir . $row . '/') : fsize($dir . $row)); ?></td>								<td><?php echo (is_dir($dir . $row) ? 'File Folder' : getExt($row) . ' File'); ?></td>								<td><?php echo date('F d Y H:i:s', filectime($dir . $row)); ?></td>						</tr><?php				$i++;		}}else{?>						<tr>								<td colspan="5"><div class="error"><h4>Directory is Empty</h4> <p>No Files or Folders in here.</p></div></td>						</tr><?php}?>				</table>		</div></body></html>

Link to comment
Share on other sites

If you want the script to be set up like in the first post, then you're not just giving it the filename to load. That's not what the original script does. The original script outputs the data for the image. You can get the data yourself using file_get_contents, that's what I was trying to show. If you want to write out the filename instead of doing it the way it was originally set up then that's something completely different then what you have now. That means that this code will only work if you're linking like this:<img src="index.php?i=<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>" alt="<?php echo $row; ?>">i.e., linking to the PHP file that gets the image data. If you want to link to the image directly then that's not the same code you're using now.

Link to comment
Share on other sites

Whoops posted the wrong script. The last one I did is the one you shown but not working :)When I look at the HTML it shows a good result but doesnt show the image at all.

								<td><img src="index.php?i=jpg" alt="tanya.jpg"></td>								<td><a href="./tanya.jpg">tanya.jpg</a></td>								<td align="right">195.491 KB</td>								<td>jpg File</td>								<td>March 23 2010 01:41:31</td>

Maybe I lost the way wich what iam doing, Or there is just something wrong i dont see at all.So this is what i got now how it was in start but with your tag you shown:

$img['img'] = file_get_contents('_img/image.png');

But it just gives the same result images wont show up.Latest Code Parts:

<?phperror_reporting(E_ALL);if(IsSet($_GET['i'])){		$i = trim($_GET['i']);		$img['img'] = file_get_contents('_img/image.png');		$img['htm'] = file_get_contents('_img/project.png');		$img['zip'] = file_get_contents('_img/package.png');		$img['dir'] = file_get_contents('_img/folder.png');		$img['<x>'] = file_get_contents('_img/folder.png');		$img['rar'] = &$img['zip'];		$img['tar'] = &$img['zip'];		$img['html'] = &$img['htm'];		$img['php'] = &$img['htm'];		$img['asp'] = &$img['htm'];		$img['jpg'] = &$img['img'];		$img['gif'] = &$img['img'];		$img['png'] = &$img['img'];		$img['bmp'] = &$img['img'];		if(IsSet($img[$i]))		{				$d = &$img[$i];		}		else		{				$d = &$img['<x>'];		}		header('Content-type: image/png');		header('Content-Disposition: attachment; filename="' . $i . '"');		exit;}

HTML Output Part:

<?phpif(IsSet($show)){		$i = 0;		foreach($show as $row)		{				$tr_class = ($i % 2 ? 'row1' : 'row2');?>						<tr class="<?php echo $tr_class; ?>">								<td><img src="index.php?i=<?php echo (is_dir($dir . $row) ? 'dir' : getExt($row)); ?>" alt="<?php echo $row; ?>"> </td>								<td><a href="<?php echo (is_dir($dir . $row) ? 'index.php?dir=' . $dir . $row : $dir . $row); ?>"><?php echo $row; ?></a> </td>								<td align="right"><?php echo size(is_dir($dir . $row) ? dsize($dir . $row . '/') : fsize($dir . $row)); ?></td>								<td><?php echo (is_dir($dir . $row) ? 'File Folder' : getExt($row) . ' File'); ?></td>								<td><?php echo date('F d Y H:i:s', filectime($dir . $row)); ?></td>						</tr><?php

Link to comment
Share on other sites

Ok first of all the

echo $d;

place also did not helped at all. But may worked after all.But founded something why it did not work.I was checking the URL's of the extension icons. and one ".png" wasn't in the _img directory so that image did not exist. "because i still did not added all extension name icons"And because the image was not in that direcotry it caused to fail loading all other images.Still weird,Anyways,About hiding I tried to find some on the php.net site but all members has a way other scripting style than my friend did years ago. "sadly he wont do the php anymore because he don't like it anymore".Problem is i cant find a way to get hiding the index.php "this is the indexer script" and a directory name like "_img" or something else.

Edited by Ziegel
Link to comment
Share on other sites

sadly he wont do the php anymore because he don't like it anymore
Yes, I can see that he's a fan of VB more than PHP. I've never seen anyone except VB programmers use the "<>" operator, everyone else uses "!=" for not equal.This is the part that creates the list of things to show:
$handle = opendir($dir);while(false !== ($read = readdir($handle))){		if($read <> '.' && $read <> '..')		{				$show[] = $read;		}}

There's already one if statement there which checks to make sure the item is not "." or "..", so you can add more checks there to filter out more things you don't want to show. You can check for "index.php", or your directory name, or you can use the is_dir function to check for any directory.

Link to comment
Share on other sites

Yes, I can see that he's a fan of VB more than PHP. I've never seen anyone except VB programmers use the "<>" operator, everyone else uses "!=" for not equal.This is the part that creates the list of things to show:
$handle = opendir($dir);while(false !== ($read = readdir($handle))){		if($read <> '.' && $read <> '..')		{				$show[] = $read;		}}

There's already one if statement there which checks to make sure the item is not "." or "..", so you can add more checks there to filter out more things you don't want to show. You can check for "index.php", or your directory name, or you can use the is_dir function to check for any directory.

Thanks. It works perfect now. just added some new if($read <> '.' && $read <> '..') lines with the folders and files that needs to be hidden and works like a charm so far :)Thanks again
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

×
×
  • Create New...