Page 1 of 1

Making this script show the results from its directory

Posted: Sat Nov 27, 2004 8:11 pm
by Abz
please could you help me out with this script i got from a web site,

its very useful and very simple, iv spent hours on end trying to make the script use the files in the directory it is in, and not the directory it is called from, what i have is a test/index.PHP page that includes the Download lister php script with in it, however when i do this the download script uses the file test/index.php directory insted of looking into its won directory where it is placed. test/dl/download.php

could anyone suggest a soultion or another script that would do the same job,
this script looks for txt fils and the corsponding avi file name and lists it, hence why it makes my life easier

am not very good with php but i do try integrating it, any help would be much appreciated, many thanks

Abs
http://www.3dnuta.com

Code: Select all

<?PHP 

$handle=opendir("."); 
while (($file = readdir($handle))!==false){ 
rtrim($file); 
if($file=="*.*"){ 
$file=readdir($handle); 
$file=readdir($handle); 
} 
if($file=="hits.txt"){ 
$file=readdir($handle); 
} 
if(eregi("[a-zA-Z0-p_-]*.txt",$file)!==false){ 
$spliter=explode(".",$file); 
$filea="$spliter[0].avi"; 
$filei="TEXT INFO"; 
$filez="$spliter[0].avi"; 
$size=filesize($filez); 
$size=($size/1024); 
$size=round($size,1); 
$info=" Text info files have not yet been created.."; 
echo "<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS=TABLEMAIN><TR>"; 
echo "<TD CLASS=TDTOP colspan=1><IMG SRC="3dsmax/mov/blank.gif" width=1 height=20></TD>"; 
echo "<TD CLASS=TDFILESIZE WIDTH=30%></TD></TR>"; 
echo "<TR><TD CLASS=TDTITLECONTENT>"; 
echo "<img src="hiddin/box.gif"><IMG SRC="3dsmax/mov/blank.gif" width=5 height=1><A HREF="" onClick="window. open('$filea','cal','width=600,height=400,status=n

o,scrollbars=yes,resizable=yes,toolbar=no,location

=no,directories=no');return false">$spliter[0]</A></B></TD><TD CLASS=TDFILESIZE>Size: $size Kb"; 
echo "</TD></TR>"; 
echo "<TR><TD colspan=2 width=100% CLASS=TDCONTENT>"; 
$filer="$file"; 
$file=file($filer); 
$sline=0; 
$count=count($file); 
$eline=$count; 
$i = $count; 
for($j=$sline;$j<$eline;$j++){ 
echo "$file[$j]"; 
} 
echo "</TD></TR>"; 
echo "<TR CLASS=TDBOT>"; 
echo "<TD CLASS=TDBOT>"; 
echo "<IMG SRC="3dsmax/mov/blank.gif" width=1 height=20>"; 
echo "<TD CLASS=TDDOWNLOAD><A HREF="" onClick="window. open('$filea','cal','width=600,height=400,status=n

o,scrollbars=yes,resizable=yes,toolbar=no,location

=no,directories=no');return false">[] PLAY</A></TD>"; 
echo "</TD></TR></TABLE>"; 

} else { 

} 

} 

?> 
-->
Av attached the script in question and you could see the script error on this page using the include method:
http://63.247.87.234/~kingabz/3dnut...o/3dsmaxmov.php
and here is the same page but using the readfile method,
http://63.247.87.234/~kingabz/3dnut...3dsmaxmovrd.php

Am so crap at this.....
__________________
Abs
http://www.3dnuta.com



__________________
Abs

Posted: Sat Nov 27, 2004 8:23 pm
by rehfeld
you could make it into a function, and then pass the directory to read from to it


Code: Select all

<?php

<?PHP 

function output_file_stuff($directory) {

$handle=opendir($directory); 
while (($file = readdir($handle))!==false){ 
rtrim($file); 
if($file=="*.*"){ 
$file=readdir($handle); 
$file=readdir($handle); 
} 
if($file=="hits.txt"){ 
$file=readdir($handle); 
} 
if(eregi("[a-zA-Z0-p_-]*.txt",$file)!==false){ 
$spliter=explode(".",$file); 
$filea="$spliter[0].avi"; 
$filei="TEXT INFO"; 
$filez="$spliter[0].avi"; 
$size=filesize($filez); 
$size=($size/1024); 
$size=round($size,1); 
$info=" Text info files have not yet been created.."; 
echo "<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0 CLASS=TABLEMAIN><TR>"; 
echo "<TD CLASS=TDTOP colspan=1><IMG SRC="3dsmax/mov/blank.gif" width=1 height=20></TD>"; 
echo "<TD CLASS=TDFILESIZE WIDTH=30%></TD></TR>"; 
echo "<TR><TD CLASS=TDTITLECONTENT>"; 
echo "<img src="hiddin/box.gif"><IMG SRC="3dsmax/mov/blank.gif" width=5 height=1><A HREF="" onClick="window. open('$filea','cal','width=600,height=400,status=n

o,scrollbars=yes,resizable=yes,toolbar=no,location

=no,directories=no');return false">$spliter[0]</A></B></TD><TD CLASS=TDFILESIZE>Size: $size Kb"; 
echo "</TD></TR>"; 
echo "<TR><TD colspan=2 width=100% CLASS=TDCONTENT>"; 
$filer="$file"; 
$file=file($filer); 
$sline=0; 
$count=count($file); 
$eline=$count; 
$i = $count; 
for($j=$sline;$j<$eline;$j++){ 
echo "$file[$j]"; 
} 
echo "</TD></TR>"; 
echo "<TR CLASS=TDBOT>"; 
echo "<TD CLASS=TDBOT>"; 
echo "<IMG SRC="3dsmax/mov/blank.gif" width=1 height=20>"; 
echo "<TD CLASS=TDDOWNLOAD><A HREF="" onClick="window. open('$filea','cal','width=600,height=400,status=n

o,scrollbars=yes,resizable=yes,toolbar=no,location

=no,directories=no');return false">[] PLAY</A></TD>"; 
echo "</TD></TR></TABLE>"; 

} else { 

} 

} 


}



// you still need to include this file exactly like you have been doing
// a function will not automatically execute, you need to call it like so

$directory = 'your/directory/to/read';

output_file_stuff($directory);






?> 

?>

when you "include" a file, think of the file as simply being cut and pasted into the file which includes it. that is essentially what happens. so when you were doing:
opendir(".");

you were openeing the directory in which the parent script was located in.

Sweet as Honey and Happy as Larry its WORKIING

Posted: Sun Nov 28, 2004 5:45 am
by Abz
hello,

thanks alot for your help pal, iv used your method and mixed it in with a suggestion from http://codewalkers.com/forum/index.php? ... lm=default

i thought the day will never come when i get this thing to work, thanks alot for your help, this script is now woth being used,

am just wondering,

if i wanted to make the script echo(display a thumbnail) that corosponds to that txt file how would i go about such a thing, or is it too much to do, am just trying to make this script self dependant and make my life easier by having to place an image/thumbnile in the directory with TXT file and make it display it, this way i dont have to include the image file into every TEXT file,

Please dont feel obliged to answer this, you have done more than enougg in helpping me, thanks alot for everything.

ill be thanking everyone who helped me in this script, and have page with links to this site,

thanks again. :)

Abz, London, UK.