Showing the uploaded Files. index.php in Uploads directory.
Moderator: General Moderators
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
Showing the uploaded Files. index.php in Uploads directory.
i have a upload script, and i wana have a "index.php" INSIDE the "uploads/" directory that shows the files, but in an organized manner, and has links on the files, To the files. here is my current upload script:
http://www.csscobalt.com/uploads/upload_php.txt
and what i was thinking, was that somehow, instead of listing the files in the Dir, every time something is uploaded, it simply adds the upload to the index.php file. but i don't even know where to begin.
any help?
http://www.csscobalt.com/uploads/upload_php.txt
and what i was thinking, was that somehow, instead of listing the files in the Dir, every time something is uploaded, it simply adds the upload to the index.php file. but i don't even know where to begin.
any help?
If you're meaning a script that will read the contents of the uploads directory.. readdir() would be useful.
I think i read a bit too much into the question, but if you're wanting the index.php file to not read the directory, but still list contents, you will need to set a script that reads the directory and writes the file up on CRON.
I think i read a bit too much into the question, but if you're wanting the index.php file to not read the directory, but still list contents, you will need to set a script that reads the directory and writes the file up on CRON.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
=/ I'm a bit confused.
The reason i'm confused is because I *think* you're a bit confused on what you want to do (well, how you want to do it). By using this following piece of code on /uploads/index.php, you can list the entire contents of the directory.
The reason i'm confused is because I *think* you're a bit confused on what you want to do (well, how you want to do it). By using this following piece of code on /uploads/index.php, you can list the entire contents of the directory.
Code: Select all
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
?>Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
your exactly correct, i am confused on how i want to do it. but let my try again:
here is the process:
1) user will upload a file with my working upload script
2) the script will then log the name, and send that name over to "index.php" in the "uploads/" directory, which will then add that name to the list.
kinda like what u had, but this way i can add like <br> and other html code so it's not all jumbled up
here is the process:
1) user will upload a file with my working upload script
2) the script will then log the name, and send that name over to "index.php" in the "uploads/" directory, which will then add that name to the list.
kinda like what u had, but this way i can add like <br> and other html code so it's not all jumbled up
You can do that using the script I had. Modify it a bit..
That will put line breaks in there. You can even link to the uploaded file.
Like that.
However if you wish to go about it by updating the file. Then you will need to read the directory on a cron script and have that script write to the index.php file (which is much more complicated than the codes above.. but can be done).
Hope that helps a bit. =]
Code: Select all
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file<br />";
}
}
closedir($handle);
}
?>Code: Select all
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<a href=\"$file\">$file</a><br />";
}
}
closedir($handle);
}
?>However if you wish to go about it by updating the file. Then you will need to read the directory on a cron script and have that script write to the index.php file (which is much more complicated than the codes above.. but can be done).
Hope that helps a bit. =]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
I forgot to escape the quotes. I updated the code above to fix that error. =]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
k, i fixed it just b4 reading it ur post
. but i just did this:
and it worked. so wutev. but is there a better/worse way to do it?
and also, that code displays files that are in directories as well :/ and i don't want that. for example,
it's here:
/uploads/index.php
and it displays files even here:
/uploads/files/personal/etc/
and i JUST want it to display files in:
/uploads/
so how do i fix that?
Code: Select all
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "<a href=" . $file . ">" . $file . "</a><br/>";
}
}
closedir($handle);
}
?>and also, that code displays files that are in directories as well :/ and i don't want that. for example,
it's here:
/uploads/index.php
and it displays files even here:
/uploads/files/personal/etc/
and i JUST want it to display files in:
/uploads/
so how do i fix that?
Last edited by JustinMs66 on Mon Sep 11, 2006 11:44 pm, edited 1 time in total.
That's pretty much the only way to do it, unless you want to store the filenames in a database as they're uploaded. Then query the database on index.php.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm
Code: Select all
<?php
if ($handle = opendir('uploads')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && !is_dir($file)) {
echo "<a href=" . $file . ">" . $file . "</a><br/>";
}
}
closedir($handle);
}
?>Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- JustinMs66
- Forum Contributor
- Posts: 127
- Joined: Sun Sep 03, 2006 4:18 pm