[ shams @ 13.10.2006. 12:14 ] @
Pozdrav,
nisam programer ali znam ponešto u PHPu, i uglavnom koristim gotove php skripte. Naleteo sam na ovu skriput i skroz mi je korisna, samo bih voleo da je izmenim/doradim.

Voleo bih da imam veću kontrolu nad tim šta sve skripta prikazuje u određenom folderu. Ona sad pokazuje sve što se tu nalazi - e sad da li može da se isključe fajlovi sa određenom ekstenzijom (ili da prikazuje samo fajlove određene ekstenzije - šta je lakše), ili da prikazuje samo listing direktorijuma (bez ikakvih fajlova)??

Ako neko ima vremena i želje da doradi ovu skriptu .. .. unapred zahvalan.

Code:

<? 
error_reporting (E_ALL ^ E_NOTICE);
$mode = $HTTP_GET_VARS["image"]; 
$show_select="true"; // put "true" to show display box or "no" to hide.
$show_search = "true"; // put "true" to show search or "no" to hide.
$show_filenames = "no"; /* when the display is on Titles, put "true" to have text at the top of 
                          the Tite with the filename, put "no" to hide the filename only for non image files.*/
$otherpath="";// put the path where you want the directory to view
$thum_width=100; 
$thum_height=90;
$rows=6; // When in titled display, this is how many pictures will be in a row.

//do not edit anything below this line

$S = $HTTP_GET_VARS["S"]; 
$view = $HTTP_GET_VARS["view"]; 
$mode= $HTTP_GET_VARS["mode"]; 
$showonly= $HTTP_GET_VARS["showonly"]; 

if("$mode" !== "image"){

$path =str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
echo "<title> Directory of $path</title>";
if (!isset($view)){  $view = details; }
if (!isset($S)){ $S =N; }

function wsort($letter,$ww){
global $S,$A,$view,$showonly;
if($A == "" && $S == $letter){ $extra="&A=D"; }
echo "<A HREF=\"?S=$letter&view=$view$extra&showonly=$showonly\">$ww</A>";
}

function viewoption($value,$wrd){
global $view;
if("$view" == "$value" ){ $sel = selected;  }
echo "<option value=\"$value\" $sel>$wrd \n";
}


$dir="./";

$dh  = @opendir($dir);
$i=0;
while (false !== ($dirfile = @readdir($dh))) {
if($dirfile !== '..' && $dirfile !== '.' ){
if($showonly){ 
if(@eregi("$showonly", $dirfile )){ $dirfile =$dirfile; } else { $dirfile = "";  }

}
if("$dirfile" !== ""){

switch ($S) {
case N:
$files[$i][name] = $dirfile;
$files[$i][fd] = @filemtime($dirfile);
$files[$i][size] = @filesize($dirfile);
break;
case M:
$files[$i][fd] = @filemtime($dirfile);
$files[$i][size] = @filesize($dirfile);
$files[$i][name] = $dirfile;
break;
case S:
$files[$i][size] = @filesize($dirfile);
$files[$i][name] = $dirfile;
$files[$i][fd] = @filemtime($dirfile);
break;
}//end case

$sumsize[] =@filesize($dirfile);

$i++;

}
}
}
if(empty($files)){ $isempty = "yes"; }

function filesizepre($filesize){ return round( ($filesize / 1024),1  ).k;  }

?>


<? if($show_search == true){ ?>

<?  } ?>

 <H1>Index of <? echo $path ?> </H1> 
 <? if("$show_search" == "true"){ ?>
 <form name="form1" method="get" action="">

 <input type="submit" name="Submit" value="File Search ">
 <input name="showonly" type="text" id="showonly" size="15" value="<? echo $showonly  ?>"> 
 <br>
<? }else{

echo "<input name=showonly type=hidden value=\"$showonly\">";

} ?>

 <input name="A" type="hidden" value="<? echo $A ?>">
<input name="S" type="hidden" value="<? echo $S ?>">

<? if("$show_select" == "true"){ ?>
<select name="view" onChange="document.form1.submit()">

<? viewoption(image,"Image Preview"); ?>
<? viewoption(details,"Details"); ?>
<? viewoption(titles,"Titles"); ?>
</select>
<? } ?>
<font color="#376D95" size=2><em><? if("$showonly" ==""){ echo  'Files in directory:'; }else{ echo "Files Showing:"; } ?> <? echo sizeof($files); ?>  <?  if("$showonly" ==""){  echo 'Directory Size:'; }else{ echo "Sorted Size:"; } ?> <?  echo filesizepre(@array_sum($sumsize)) ?> <? if("$showonly" && "$isempty"  !==""){ echo " - File Search Provided 0 Results."; } ?>
<br>
</em></font>

</form>
 <PRE><? wsort(N,Name); ?>                                    <? wsort(M,"Last Modified"); ?>      <? wsort(S,"Size"); ?>  <HR>
<?





if($A == ""){ 
@sort($files);
}else{

@rsort($files);
}
if(!$isempty){
$rt=1;
foreach($files as $filename){



$getname22 = substr("$filename[name]", 0, 22); 
if(strlen($filename[name]) > 22){ $prefilename = "$getname22..."; }else{ $prefilename = $getname22; }


if($view == image ){
echo "<br><a href=\"$filename[name]\"><img src=\"".$_SERVER['PHP_SELF']."?view=$view&mode=image&image=$filename[name]\" width=$thum_width height=$thum_height border=0></a><br>";

}
if($view == details){


echo "<br><IMG SRC=\"/icons/portal.gif\" ALT=\"[$exten]\"> ";
}

if($view == titles){
$br='';
if($rt == $rows){ $br="<br>"; $rt =0; }
echo "<a href=\"$filename[name]\"><img src=\"".$_SERVER['PHP_SELF']."?view=$view&mode=image&title=yes&image=$filename[name]\" width=$thum_width height=$thum_height border=0></a>  $br";


}else{

echo "<A HREF=\"$filename[name]\">$prefilename</A>      ". str_repeat(" ",(25 - strlen($prefilename))) ."    ".date("j-M-y h:iA", $filename[fd])."   ".(filesizepre($filename[size]) )."  ";
}

$rt++;
}
}//is empty 
?>

</PRE><HR><? echo $_SERVER['SERVER_SIGNATURE']; ?>



<?

}//end of mode if nothing
if("$mode" == "image"){
$image = $HTTP_GET_VARS["image"]; 
$view = $HTTP_GET_VARS["view"]; 

$exten = strtoupper(strstr($image, '.'));
switch ($exten) {
case '.JPEG':
$imgd = @imagecreatefromjpeg($image);
break;
case '.JPG':
$imgd= @imagecreatefromjpeg($image);
break;
case '.GIF':
$imgd = @imagecreatefromgif($image);
break;
case '.PNG':
$imgd = @imagecreatefrompng($image);
break;
}

$im = imagecreatetruecolor($thum_width,$thum_width);

$size = @getimagesize($image);

$getname22 = substr(eregi_replace("$exten","",$image), 0, ($thum_width / 10)); 

if(strlen(eregi_replace("$exten","",$image)) > ($thum_width / 10)){ $w_er = "$getname22..$exten"; }else{ $w_er = $getname22.$exten; }

if("$imgd" == ""){  $w_er = "$image";  $white = imageColorallocate($im, 255,255,255);  $filetype="file"; }else{

$rr=@imagecolorat($imgd, 10, 4);
$cn = @imagecolorsforindex($imgd, $rr);
if("".$cn[red].$cn[green].$cn[blue]."" < "200200200"){    $white = imageColorallocate($im, 255,255,255);  }
}

@imageCopyResampled($im, $imgd , 0, 0, 0, 0, $thum_width,$thum_width, $size[0], $size[1]);


if("$view" == "titles" && "$show_filenames" == "no" && "$filetype" !== "file"){ 
$view = "image";
}
if("$view" !== "image" ){

imagestring($im,2 ,1 ,2, $w_er, $white);
imagestring($im,2,1 ,2, $w_er, $white);
}
imagejpeg($im);
imagedestroy($im);

}//end of mode
?>
[ shams @ 14.10.2006. 23:05 ] @

ok jasno , niko nema vremena,
[ sale83 @ 15.10.2006. 01:42 ] @
Evo bez testiranje te tvoje scripte...

Recimo ovako nesto:

Ispod ove linije
Code:

$rows=6; // When in titled display, this is how many pictures will be in a row.

Dodaj ovu liniju:
Code:

// Sta oces da prikazujes
$Prikazi=array(".txt",".jpeg",".jpg",".gif");



I onda lepo ovo:

Code:


while (false !== ($dirfile = @readdir($dh))) {
if($dirfile !== '..' && $dirfile !== '.'){



Promenis, izmenis (dodas) pa na kraju izgleda ovako:
Code:


while (false !== ($dirfile = @readdir($dh))) {
$eks = strrchr($dirfile,'.');
if($dirfile !== '..' && $dirfile !== '.' && in_array($eks,$Prikazi)){




Eto tako nekako mozes da resis...
[ shams @ 16.10.2006. 10:28 ] @

tnx tnx tnx tnx tnx