PDA

View Full Version : Display RAR Filename?



moose86
02-17-2013, 01:15 AM
Hi all

Is it possiable to display a RAR filename on a PHP page from a directory?

i.e i have name.php and i add welcome.rar to a directory on the server and the php automatically creates a new item within the php page

before:

item 1
item 2

After:

welcome
item 1
item 2

Thanks guys :)

djr33
02-17-2013, 02:36 AM
I don't understand the question. Why does it matter what type of file it is? And how would you know which file if you don't know the filename? It seems like you just could use echo $filename;, assuming you have $filename defined for other reasons.

Or do you want to actually know the contents or a .rar file? That would require an additional library, I think, and I've only done that for .zip files, but there's probably something for .rar files too. You can search for "read .rar php" and see what comes up.

moose86
02-17-2013, 02:45 AM
yer thanks, i forgot about echo lol (im not to good with php)

moose86
02-17-2013, 05:50 AM
ok, i searched and searched but didnt find any that worked, my main goal here is:

A page to display all the files in a certain folder and a link next to it to click so the user can download that (single) file.

but it has to be php as it has to update itself automatically when a new file has been put into that directory.

Thanks :)

djr33
02-17-2013, 06:05 AM
You should be able to adapt some of the code from this page:
http://php.net/manual/en/function.readdir.php

fastsol1
02-17-2013, 10:44 PM
$dir = 'directory/you/want';
foreach(scandir($dir) as $file)
{ echo '<a href="'.$dir.'/'.$file.'">'.$file.'</a><br>'; }

If you want to force the file to be downloaded, that's a little more involved. HTML5 has a new attribute to force download but not all browsers support it yet.

djr33
02-17-2013, 11:11 PM
If you want to force the file to be downloaded, that's a little more involved. HTML5 has a new attribute to force download but not all browsers support it yet. I don't think that would be relevant with .rar files-- no browser (that I know of) can view them natively, so they'd be saved (perhaps to a temporary directory, which would be allowed with force-download anyway) and extracted on the user's computer.