Page 1 of 2

Show items in directory with links.

Posted: Wed Aug 25, 2004 9:19 am
by djohnson
I have a script that shows items in a directory. Now i want to beable to select them for downloading.

This is my script.

Code: Select all

<?
foreach ( glob ( '/path/*' ) as $item ) echo $item . '<br />';
?>

What can i add to give me links to these files. ?

Posted: Wed Aug 25, 2004 9:33 am
by John Cartwright

Code: Select all

<?php
foreach ( glob ( '/path/*' ) as $item ) 
{
      echo "<a href='/path/".$item."'>".$item."</a> <br />";
}
?>

Posted: Wed Aug 25, 2004 10:28 am
by feyd
glob returns full path... so you'll need to strip everything leading up to that directory off and add in the web accessible directory structure instead..

Ok now what about downloading the files in that dir.

Posted: Wed Aug 25, 2004 12:27 pm
by djohnson
Ok now what about downloading the files in that dir. Do i need to put the server name in there like feyd said? Well i did this

Code: Select all

<?php 
foreach ( glob ( 'http://server/path/*' ) as $item ) 
{ 
      echo "<a href='/path/".$item."'>".$item."</a> <br />"; 
} 
?>
Now it just shows a blank directory. Do i need to specify permissions on the web server? The web sever is IIS 5.0.


?>

Posted: Wed Aug 25, 2004 12:31 pm
by feyd
glob is for local paths only.

Posted: Wed Aug 25, 2004 1:58 pm
by djohnson
Sorry im new to this what would i use instead of it?

Posted: Wed Aug 25, 2004 1:59 pm
by ast3r3x
This thread seems relevant for my question. In OS X, I know .app's are just really directories. But is there anyway to have the link download the whole app instead of treating it like a directory and showing the package contents?

Posted: Wed Aug 25, 2004 2:08 pm
by feyd
djohnson wrote:Sorry im new to this what would i use instead of it?
ex. 'C:/Program files/Apache/'

Posted: Wed Aug 25, 2004 2:09 pm
by feyd
ast3r3x wrote:This thread seems relevant for my question. In OS X, I know .app's are just really directories. But is there anyway to have the link download the whole app instead of treating it like a directory and showing the package contents?
similar, but not..

have the script package the directory/app into a compressed archive for a nice neat download.

Posted: Wed Aug 25, 2004 2:54 pm
by djohnson
i think i just lost it.
this is what i have

Code: Select all

<?php 
foreach ( glob ( 'c:/inetpub/phproot/files/*' ) as $item ) 
{ 
      echo "<a href='c:/inetpub/phproot/files/".$item."'>".$item."</a> <br />"; 
} 
?>
it shows the links, but when i selct the file with the line, it shows it trying to access file:///c:/inetpub/phproot/files/c:/inetpub/phprooot/files/fileselected.php

Posted: Wed Aug 25, 2004 3:02 pm
by feyd
feyd wrote:glob returns full path... so you'll need to strip everything leading up to that directory off and add in the web accessible directory structure instead..

Posted: Wed Aug 25, 2004 3:06 pm
by djohnson
Hey man thanks for your quick response.

Code: Select all

<?php 
foreach ( glob ( 'http://63.82.108.66/files/*' ) as $item ) 
{ 
      echo "<a href='http://63.82.108.66/files/".$item."'>".$item."</a> <br />"; 
} 
?>
shows no files when i select it.

Posted: Wed Aug 25, 2004 3:20 pm
by feyd
:?

Code: Select all

<?php
$dir = 'c:/inetpub/phproot/files/';
foreach ( glob ( $dir . '*' ) as $item )
{
      echo "<a href='http://63.82.108.66/files/".preg_replace('#^' . preg_quote($dir,'#').'#',$item)."'>".$item."</a> <br />";
}
?>

Posted: Wed Aug 25, 2004 3:41 pm
by djohnson
Awsome i can now download files. But i do get one error.

Warning: Wrong parameter count for preg_replace() in C:\Inetpub\phproot\Files\view2.php on line 14
c:/inetpub/phproot/files/view.php

Thanks alot man

Posted: Wed Aug 25, 2004 3:53 pm
by feyd
oops..

preg_replace('#^' . preg_quote($dir,'#').'#','',$item)