Forum Moderators: coopster

Message Too Old, No Replies

Working with directories

help me get started on working with directories

         

bysonary

8:23 pm on Jan 23, 2007 (gmt 0)

10+ Year Member



Hello,

I am looking to write a very basic script that will simply list the entire contents of a directory/folder and also put a little button/text next to each listed item in the dir/folder with the option to view and delete.

Basically I want it to look something like this

photo1.jpg....view ¦ delete
photo2.jpg....view ¦ delete
photo3.gif....view ¦ delete
photo4.png....view ¦ delete

you get the idea?

can anyone tell me first of all if this is possible and secondly how I might go about doing it or where I might look for inspiration?

Any help would be much appreciated

Thank you

barns101

9:30 pm on Jan 23, 2007 (gmt 0)

10+ Year Member



Yes it is possible, I have seen PHP scripts that list the contents of directories and so adding view and delete links wouldn't be difficult. I don't remember where I saw the scripts but a Google search for "PHP list directory contents" (without the quotes) will bring up many results.

EDIT:
opendir() [php.net] should show you everything you need. ;)

henry0

11:05 pm on Jan 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Aren't you too drastic?
I will make it a two steps process.
One) I suppose that the img path is loaded in a DB, then you could add a col "published" (y or n)

Your query to show the imgs will state "where published='$published' "; (default n, so you may publish and un-publish)
Two) if so (as above mentioned) A) un-publish by updating "published to "n"
and B) after a while if you really want to del it then go ahead

jatar_k

11:27 pm on Jan 23, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



deleting is as simple as having a link to a delete script which uses the unlink() function, though you may find permission problems depending on what user the image is uploaded as against what user php runs as.

as far as listing from a dir, try this search [google.com], there are a bunch of threads that have snippets

bysonary

11:37 am on Jan 26, 2007 (gmt 0)

10+ Year Member



Is it possible to put the items in the directory into a HTML list box or something similar? If so any hints?

bysonary

11:26 pm on Jan 28, 2007 (gmt 0)

10+ Year Member


i got it no need to reply incase anyone is curious..

<form method="post" action="test.php">
<select name="OS" SIZE=3>

<?
$dir = "/home/www/juttuffi/gallery/images";
$d = dir($dir);
$type = array('jpeg', 'jpg', 'gif', 'bmp', 'png');

while($entry = $d->read())
{
if ($entry!= "." && $entry!= ".." && array_search($type)!== false)
{
echo "<option>".$entry."</option>";
}
}
$d->close();
?>

</select>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

the array_search function in the above doesn't work but I am working on it.