Jump to content

Folders / Files -- href


rbvinc

Recommended Posts

I 'googled' the followind code, "php / folders / href" links.

With "Respect" to who ever created this, I am trying to

learn php / folders / href links. Thank you to you.

 

This code does all the job all the way, but at the end, the

file names are not ending up with <a href=....> link,

where I can click on these last step files and open it.

(Mostly I have pdf files). As well image is not showing

at the end step infront of the file name. (This code

involves Javascript also).

 

Need expertise help to do what I am looking for.

Please check the code and please fix it.

Thank you in advance.

*********************

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

 

<html>

<head>

<title>Untitled</title>

<link rel="STYLESHEET" type="text/css" href="css/cbStyles.css">

</head>

 

<body bgcolor="#ffefd5">

 

 

<?

 

//default directory when the text field has no input

 

$def='C:/';

 

// directory path can be either absolute or relative

 

function lister($dirPath){

 

// open the specified directory and check if it's opened successfully

 

if ($handle=opendir($dirPath)) {

 

// keep reading the directory entries 'til the end

 

while (false !== ($file = readdir($handle))) {

 

// just skip the reference to current and parent directory

 

if ($file != "." && $file != "..") {

 

if (is_dir("$dirPath/$file")) {

 

// found a directory, do something with it?

 

echo '<img src="icons/fRed.png"/><a href="#" onclick="javascript: r(\''.$dirPath.$file.'/\'); d()">'.$file.'</a><br/>';

 

} else {

 

// found an ordinary file

 

$extensions=array('doc','jpg','png','pdf','xls');

 

$ext=$file;

 

$pos=strrpos($ext,'.');

 

$ext=substr(substr($ext,$pos),1);

 

if(in_array(strtolower($ext),$extensions)){

 

echo '<img src="icons/'.$ext.'.png"/>  '.$file.'<br/>';

 

}else{

 

echo '<img src="icons/aGreen.png"/>  '.$file.'<br/>';

 

}

 

}

 

}

 

}

 

// ALWAYS remember to close what you opened

 

closedir($handle);

 

}

 

}

 

?>

 

<html>

 

<head>

 

<title>List Contents</title>

 

<link rel="icon" href="icons/logoRoundPurple.png"/>

 

<link rel="stylesheet" href="style.css"/>

 

<script type="text/javascript">

 

function r(dir){

 

document.lister.directory.value=dir;

 

}

 

function d(){

 

document.lister.submit();

 

}

 

</script>

 

</head>

 

<body><br/>

 

<table class="cells"><tr>

 

<td class="navi">

 

<div class="container">

 

<form method="post" autocomplete="off" name="lister">

 

Directory:<br/>

 

<input type="text" name="directory"/><br/><br/>

 

<input type="submit" name="list" value="LIST"/>

 

</form>

 

<br/><br/>

 

</div>

 

</td>

 

<td class="content">

 

You are currently at:<br/>

 

<div class="breadcrumbs" id="crum">

 

<?php

 

#show the breadscrumbs so as to navigate to the last directory.

 

$path=explode('/',$_POST['directory']);

 

$it=count($path);

 

for($i=1;$i<$it;$i++){

 

echo '<a href="#" onclick="r(\'';

 

for($j=0;$j<$i;$j++){

 

echo $path[$j].'/';

 

}

 

echo '\'); d();">';

 

echo '<font color=red>'.$path[$i-1].'</font>';

 

echo '</a>  <img src="icons/bBlue.png"/>';

 

}

 

?>

 

</div>

 

address: <input type="text" style="height: 22px; width: 600px;" value="<?=$_POST['directory']?>"/>

 

<br/>

 

<br/>

 

<?php

 

if($_POST['directory']==''){

 

lister($def);

 

}else{

 

lister($_POST['directory']);

 

}

 

?>

 

</td>

 

</tr>

</table>

 

</body>

 

</html>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/188452-folders-files-href/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.