Jump to content

field type for file directories


davids_media

Recommended Posts

I have created a table called directories. Now basically I have two fields;

 

dirID (INT)

directory (VARCHAR)

 

now I am fully aware this might sound like more of an SQL question but I have three physical directories:

 

db/images/web1

db/images/web2

db/images/web3

 

I have inputted them into the database but I was just wondering, how could I created a page which links those records to a directory. I want to have each row hyperlinked, with the output page displaying list of contents for each directory. How can I possibly achieve this please?

Link to comment
Share on other sites

I have created a table called directories. Now basically I have two fields;

 

dirID (INT)

directory (VARCHAR)

 

now I am fully aware this might sound like more of an SQL question but I have three physical directories:

 

db/images/web1

db/images/web2

db/images/web3

 

I have inputted them into the database but I was just wondering, how could I created a page which links those records to a directory. I want to have each row hyperlinked, with the output page displaying list of contents for each directory. How can I possibly achieve this please?

 

You first need to return your rows from the db, then create a link that will pass the directory path to a php script.

 

Creating the Link:

<html>
<body>
<a href="/directory.php?dir=<?=$row[1]?>">LINK TO DIR 1</a>
<a href="/directory.php?dir=<?=$row[2]?>">LINK TO DIR 2</a>
<a href="/directory.php?dir=<?=$row[3]?>">LINK TO DIR 3</a>
</body>
</html>

 

The Directory page: directory.php

<?php
    $dir = $_GET['dir'];
    $handle = opendir($dir);
    if ($handle) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo "$entry\n";
        }
    }
    closedir($handle);
}
?>

 

That is a basic look at how you can achieve the desired result.

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.