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
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Fri May 12, 2006 11:52 am
Hey,
im wanting to create a directory indexer, but my problem is when the directory is indexed it is indexed directly to the directory and im not wanting to put the same script in every directory. Is there any way i can use pgp GET to index the directory within the index.php (hope yee understand). So the directorys can be accessed like:
Code: Select all
www.EXAMPLE.net/index.php?dir=TEST DIRECTORY
Instead of:
Example of glob:
Code: Select all
<?php
foreach (glob("*.txt") as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
?>
Thanks in advance!
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri May 12, 2006 11:54 am
sure...just use your $_GET var for the directory name.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Fri May 12, 2006 3:48 pm
Thanks, I understand the concept of it, but i can seem to gte it working with my existing script:
Code: Select all
<?php
$location = "Library";
$dir = getcwd().'/';
$difference = 30;
$start = isset($_GET['start']) ? (int)$_GET['start'] : 0;
$end = isset($_GET['end']) ? (int)$_GET['end'] : 0;
$size = count($file_array["name"]);
if($end <= $start) {
$end = $start+30;
}
function smart_filemtime($filename) {
$time = @filemtime($filename);
if ($time) return $time;
else return time();
}
if (is_dir($dir))
{
$i = 1;
$files = glob($dir . 'Library/*');
foreach($files as $file)
{
$file_array["name"][] = basename($file);
$file_array["date"][] = filemtime($file);
}
array_multisort($file_array["date"], SORT_NUMERIC,SORT_DESC, $file_array["name"]);
//how many blocks?
$nb = count($file_array["name"]);
$nbOfBlock = intval($nb / $difference);
if(($nb % $difference) == 0)
$nbOfBlock--;
//display from where to where ?
if($_GET["p"])
$minDisplay = ($_GET["p"] - 1) * $difference;
else
$minDisplay = 0;
if(($minDisplay + $difference) > $nb)
$maxDisplay = $nb;
else
$maxDisplay = $minDisplay + $difference;
//print "min : $minDisplay max : $maxDisplay";
//display the right block
?>
<div align = "center">
<?php
//pagination
//further for the links of ps Smile
if(++$nbOfBlock)
{
for($i = 1;$i <= $nbOfBlock;$i++)
print " - <a href=\"?name=Library&file=index&p=$i\">$i</a>";
}
echo " - ";
?>
</div>
<?php
for($i = $minDisplay;$i < $maxDisplay; $i++)
{
echo "<tr style='border:1px solid #cfcfcf;background:#fcfcfc; cursor:hand\' onMouseOver=\"this.style.background='#EEEEEE'\" onMouseOut=\"this.style.background='#FFFFFF'\" onClick=\"window.location.href='modules.php?name=Library&file=file&page=".$file_array["name"][$i]."'\">
<td width=\"70%\"><a href=\"modules.php?name=Library&file=file&page=".$file_array["name"][$i]."\">".$file_array["name"][$i]."</a>
</td>
<td width=\"30%\" align=right><a href=\"$location".$file_array["name"][$i]."\">Plaintext</a> | <i>".$time.date ("F d Y", $file_array[date][$i]);
echo "</i></td>";
}
}
?>
</table>
<div align = "center">
<?php
if($nbOfBlock)
{
for($i = 1;$i <= $nbOfBlock;$i++)
print " - <a href=\"".$PHP_SELF."?name=Library&file=index&p=$i\">$i</a>";
}
echo " - ";
?>
I have tryed replacing
with
But then i get the followign error:
Code: Select all
Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /host/localhost/htdocs/modules/Library/index.php on line 44
I have tryed commenting out this line, but then nothing is displayed. I think something in the script is cntradicting something else, but im not sure why.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri May 12, 2006 7:36 pm
try echoing out the $_GET var plus your *.* to make sure it's giving you what you think it is.
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 13, 2006 7:42 am
Right, i got the first part
Code: Select all
plus your *.* to make sure it's giving you what you think it is.
But i dont quite follow the above.
I have tryed replacing
Code: Select all
$files = glob($dir . 'Library/*');
with
Code: Select all
$files = glob($dir . 'Library/$dir*');
But im still faced with the array_multisort() error and with no files being indexed.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sat May 13, 2006 10:08 am
so try what I suggested and echo it out to make sure it's what you think it is:
Code: Select all
$dir = getcwd().'/';
$dir2 = $_GET['dir'].'/';
echo 'old way '.$dir;
echo 'new way '.$dir2;
$files1 = glob($dir.'*.*');
print_r($files1);
$files2 = glob($dir2.'*.*');
print_r($files2);
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sat May 13, 2006 11:40 am
Ah, i unserstand now, but im wanting to get working along side my current script but whenever i try the phandom error message always gets displayed:
Code: Select all
Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /host/localhost/htdocs/modules/Library/index.php on line 44
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Sat May 13, 2006 1:44 pm
that error means that glob() isn't returning an array. did you try what I suggested? if so, what did it show?
ozzy
Forum Commoner
Posts: 74 Joined: Tue Apr 11, 2006 4:45 pm
Post
by ozzy » Sun May 14, 2006 9:40 am
I did what you suggested, and i got it to work, although im wanting it to work alongside with my current script but i cant seem to do that due to the error.