Jump to content

[ resolved ] Make as a clickable link!


ztealmax

Recommended Posts

Hi need a bit of help, i have this code that lists all files in a folder sorted by date!
[code]<?php
$this = $PHP_SELF;
$dir  = $DOCUMENT_ROOT."x101_news/";

$files = opendir($dir);
$file_list = array();
$file_sort = array();

if(empty($sort))$sort="name";
if(empty($r)) $r=0;

$cnt = 1;

    while ($file = readdir($files))
{
$full_path = $dir."/".$file;
if(!is_dir($full_path))
{
$ext = explode(".",$file);
$i=count($ext);
if($i>1)$file_details["ext"] = strtolower($ext[$i-1]);
$file_details["name"] = $ext[0];
$file_details["date"] = filectime($full_path);
$file_list[$cnt] = $file_details;

$key = strtolower($file_details[$sort]);
$file_sort[$cnt] = $key;

$cnt++;
}
}

if($r)arsort($file_sort);
else asort($file_sort);


?>
<link href="../webmax.css" rel="stylesheet" type="text/css">

<table width="465" border="0" cellpadding="3" cellspacing="0" class="bodytext">
  <tr>
    <td width="174"><a href="<?php print($this);?>?sort=name&r=<?php print(!$r);?>">Name</a></td>
    <td width="141"><a href="<?php print($this);?>?sort=date&r=<?php print(!$r);?>">Date</a></td>
  </tr>
  <tr bgcolor="#0033CC">
    <td height="3" colspan="5"> </td>
  </tr>
<?php
while(list($key, $value)=each($file_sort))
{
$value = $file_list[$key];
?>
  <tr>
    <td width="174"><?php print($value["name"]);?></td>

    <td width="141"><?php print(date("Y/m/d H:i",$value["date"]));?></td>
  </tr>
<?php




}
?>


</table>[/code]

however i would like to make the files clickable so i can read them with read text file thingy

That is a want to make the list clickable so it opens the document i click on!

tthis is my read text file thingy, but it has the document name already in the code
[code]
<?php
$filename = 'news/*.*';

// set file to read
$file = 'news/textdoc.txt';
// open file
$fh = fopen($file, 'r') /*or die('Could not open file!')*/;
// read file contents
$data = fread($fh, filesize($file)) /*or die('Could not read file!')*/;
// close file
fclose($fh);
// print file contents
echo $data;
?>
[/code]
anyone know a way to do this?

//Martin
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.