PDA

View Full Version : PHP <include> question


miyagi
March 24th, 2006, 04:25 PM
I'm using the <include> function to grab a directory listing from http://sentrygun.org/pics and include it as part of this website: http://sentrygun.org/web_test

However I need to fix ALL the links that the function grabs from the listing so they're not relative, but absolute (eg. /name.jpg -- to --> http://sentrygun.org/pics/name.jpg).

Could somebody write me something simple that does that?

Direhit
March 24th, 2006, 07:32 PM
Well first off that looks more like a HEADER.HTML and README.HTML addon with apache rather then a PHP script. Nonetheless just open the target directory, loop through the file and store their info in an array, foreach the array and viola. And btw, what the hell is <include> in PHP?

$path = "/usr/home/some/folder/with/read/permission/";
$dir = dir("$path");
while($files = $dir->read())
{
if($files != "." && $files != "..") {
$FolderFiles[] = "$files";
}
}
@closedir($dir);
@sort($FolderFiles);
@reset($FolderFiles);

foreach($FolderFiles as $file) {
echo '<a href="./'.$file.'">'.$file.'</a> - '.filemtime($path.$file).' - '.filesize($path.$file).' ';
}

miyagi
March 24th, 2006, 08:07 PM
cheers i may try that

thrash_head
March 24th, 2006, 09:37 PM
A include replaced the Iframe. I've seen alot of web-coders debate on which is the best... I'm not a very good coder, so i wouldn't know :P

miyagi
March 25th, 2006, 03:47 AM
seems to work, i have a few more things to ask but im not really bothered right now

http://sentrygun.org/web_test/index_mod.php

miyagi
March 25th, 2006, 04:26 PM
ok i need the description links (filename, last mod., size) to be links for sorting ascending or descending.

also, how do i get rid of folders showing up in the list? something like: if the file doesnt end in ".*" then exclude it?

any ideas?

cheers.

Direhit
March 25th, 2006, 09:02 PM
ok i need the description links (filename, last mod., size) to be links for sorting ascending or descending.

also, how do i get rid of folders showing up in the list? something like: if the file doesnt end in ".*" then exclude it?

any ideas?

cheers.
Well, for the folders, you could add a clause like so...

http://us3.php.net/manual/en/function.is-dir.php

if(!is_dir($files)) {
$FolderFiles[] = $files;
}

Or...

http://us3.php.net/manual/en/function.is-file.php

if(is_file($files)) {
$FolderFiles[] = $files;
}

As for your sorting, your best bet is to simply store all that info in a multi-dimensional array and use the key/values to sort it however you want.

http://us3.php.net/manual/en/ref.array.php

If you're really a fan of PHP, the php.net website can be an incredibly valuable source of information, learn to love it. If you enjoy doing web development type stuff, I would also recommend http://forums.devshed.com.