SimonUK
asked on
html and php file list for download
Hi all
In this question:
https://www.experts-exchange.com/questions/21833113/Automatic-file-listing-in-HTML-or-similar.html
I got some handy assistance generating an HTML page that lists all the files in a given folder, and making them available for download. The one I'm using is this one (see original thread above for author credit):
<?php
function make_row ($s) {
return "<tr><td>$s</td><td><a href='files/$s'>Download</ a></td></t r>\n";
}
$files = glob('*');
// Fetch all file names
$files = array_map("make_row", $files);
// Format the file names for output
$str = implode("", $files);
// Join the array to make it a string
$str = "<table border='1' bordercolor='white'><col style='background-color: #CCCCFF;'></col><col style='background-color: #9999FF;'></col>$str</tabl e>";
// Format it further
echo $str;
// Print the string.
?>
What I'd like to do next is:
- Specify a directory for the file listing (so I can list files from a dir other than the one the script exists in)
- Make a left-click trigger a 'Save file as...' dialog box, rather than relying on users right-clicking
- Show the date and time of the files listed
- Not show the complete path to the file on the page - just the filename. I appreciate the path has to exist in the link to the file, of course.
Thanks !
Simon
In this question:
https://www.experts-exchange.com/questions/21833113/Automatic-file-listing-in-HTML-or-similar.html
I got some handy assistance generating an HTML page that lists all the files in a given folder, and making them available for download. The one I'm using is this one (see original thread above for author credit):
<?php
function make_row ($s) {
return "<tr><td>$s</td><td><a href='files/$s'>Download</
}
$files = glob('*');
// Fetch all file names
$files = array_map("make_row", $files);
// Format the file names for output
$str = implode("", $files);
// Join the array to make it a string
$str = "<table border='1' bordercolor='white'><col style='background-color: #CCCCFF;'></col><col style='background-color: #9999FF;'></col>$str</tabl
// Format it further
echo $str;
// Print the string.
?>
What I'd like to do next is:
- Specify a directory for the file listing (so I can list files from a dir other than the one the script exists in)
- Make a left-click trigger a 'Save file as...' dialog box, rather than relying on users right-clicking
- Show the date and time of the files listed
- Not show the complete path to the file on the page - just the filename. I appreciate the path has to exist in the link to the file, of course.
Thanks !
Simon
ASKER
Hi
Thanks for your suggestions: I don't know enough about php to know how to set the directory and how to list the files in a div - the script above was written for me at the link shown, so I'd need an idea of the alterations required to the code, please!
The links to the manual are very handy though; I'll read up!
Simon
Thanks for your suggestions: I don't know enough about php to know how to set the directory and how to list the files in a div - the script above was written for me at the link shown, so I'd need an idea of the alterations required to the code, please!
The links to the manual are very handy though; I'll read up!
Simon
ASKER
Anyone able to further this, please?
Thanks
Simon
Thanks
Simon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Some observations:
-You should specify the directory where you want to browse in the variable $path, e.g. $path = "/" for root...
-The directories will not be listed
Greetings,
---murki
-You should specify the directory where you want to browse in the variable $path, e.g. $path = "/" for root...
-The directories will not be listed
Greetings,
---murki
ASKER
Thanks Murki
I've tried the code... I can get a list of files OK, and the date/time is there - but the path still appears (I only want to show the filename - is that possible?) and if I left-click, the browser locks up. It appears to be trying to open the file directly in the browser - what I want to achieve is a Save File As... dialog box when users left click.
This is because not everyone knows to right click on files to download... so they left click and the browser tries to open the file.
That said, I'm using IE7 beta, so maybe that's the problem. Will try with IE6, meantime do you have any further suggestions?
Thanks again
Simon
I've tried the code... I can get a list of files OK, and the date/time is there - but the path still appears (I only want to show the filename - is that possible?) and if I left-click, the browser locks up. It appears to be trying to open the file directly in the browser - what I want to achieve is a Save File As... dialog box when users left click.
This is because not everyone knows to right click on files to download... so they left click and the browser tries to open the file.
That said, I'm using IE7 beta, so maybe that's the problem. Will try with IE6, meantime do you have any further suggestions?
Thanks again
Simon
I get the Save As... dialog when left clicked. Have you verified this yet ?
ASKER
Still same issue but thanks for checking again... will try again with alternate setups ASAP - apols for slow response!
Simon
Simon
I'm pretty positive that my solution worked, i coded everything it was needed, so I think the points should be given to me :)
greetings,
--murki
greetings,
--murki
ASKER
I never did get it working, but ran out of time to check other platforms / versions of Explorer, so I agree that murking should get the points. I'll try further with the code and report back, and start a new thread if I need further help !
Simon
Simon
thanks simon, any other help u need, just ask...
--murki
--murki
For parts 2,4 - list the files in a div with a link to the files. Then if they click on it, they'll be prompted to download it (typically, at least...what kind of files are they? )
For part 3 - Use stat() http://us3.php.net/manual/en/function.stat.php to get the file date/time and date() http://us3.php.net/manual/en/function.date.php to display the date/time with the filenames.