PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 9:19 am
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. ?
John Cartwright
Site Admin
Posts: 11470 Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:
Post
by John Cartwright » Wed Aug 25, 2004 9:33 am
Code: Select all
<?php
foreach ( glob ( '/path/*' ) as $item )
{
echo "<a href='/path/".$item."'>".$item."</a> <br />";
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 10:28 am
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..
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 12:27 pm
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.
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 12:31 pm
glob is for local paths only.
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 1:58 pm
Sorry im new to this what would i use instead of it?
ast3r3x
Forum Commoner
Posts: 95 Joined: Thu Aug 19, 2004 8:36 pm
Post
by ast3r3x » Wed Aug 25, 2004 1:59 pm
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 2:08 pm
djohnson wrote: Sorry im new to this what would i use instead of it?
ex. 'C:/Program files/Apache/'
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 2:09 pm
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.
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 2:54 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 3:02 pm
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..
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 3:06 pm
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 3:20 pm
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 />";
}
?>
djohnson
Forum Newbie
Posts: 9 Joined: Tue Aug 24, 2004 11:32 am
Location: here
Post
by djohnson » Wed Aug 25, 2004 3:41 pm
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
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Aug 25, 2004 3:53 pm
oops..
preg_replace('#^' . preg_quote($dir,'#').'#','',$item)