0
<?

$start = $_GET[start] ? $_GET[start] : 0 ;

$sortby = $_COOKIE[sortby] ? $_COOKIE[sortby] : "name" ;
if($_GET[sortby]){
    $sortby = $_GET[sortby];
    setcookie("sortby", $_GET[sortby], time()+86400 );
    header("location: index.php");
}




$od = opendir("./");
while($file = readdir($od)){
    if( eregi("\.(gif|jpe?g|png)$", $file) ){
        $file2 = rawurlencode($file);
        $img_arr[$file2]            = $file;
        $img_arr_filesize[$file2]   = filesize($file);
        $img_arr_filemtime[$file2]  = filemtime($file);

        list($imagex, $imagey, $type, $attr) = getimagesize($file);
        $img_arr_sizexy[$file2]     = $imagex."x".$imagey;
    }
}



asort($img_arr);
asort($img_arr_filesize);
asort($img_arr_filemtime);


switch($sortby){
    case "time":
        $img_arr_final = $img_arr_filemtime;
        break;

    case "size":
        $img_arr_final = $img_arr_filesize;
        break;

    case "name":
        $img_arr_final = $img_arr;
        break;
}

$total_images = count($img_arr_final);

foreach($img_arr_final as $k=>$v){
    $i++;
    if($i < $start+1) continue;
    if($i > $start + $pp) break;

    $img_name = strlen($img_arr[$k]) > 18 ? substr($img_arr[$k],0,16)."..." :$img_arr[$k];

    $alt = $img_arr[$k] . " -|- Last modified: " . date("Y-m-d H:i:s", $img_arr_filemtime[$k]) . " ";

    $imgl .= "<div class=\"img_thumb\"><a href=\"$k\"><img src=\"index.php?thumb=$k\" alt=\"$alt\" title=\"$alt\" /></a><p title=\"".$img_arr[$k]."\"><strong>".$img_name.    "</strong><br /><span class=\"mini\">".$img_arr_sizexy[$k].", ".round(($img_arr_filesize[$k]/1024))." KB</span></p></div>";


}




for($p=0; $p*$pp <  $total_images ; $p++){
    $active = ($p*$pp) == $start ? "active" : "" ;
    $page_htmo .= "<a href=\"index.php?start=".($p*$pp)."\" class=\"$active pages\">".($p+1)."</a> ";
}



$arr_sortby = array("name"=>"Name", "size"=>"Size", "time"=>"Time");    

foreach($arr_sortby as $k=>$v){

    if($sortby == $k){
        $sortby_html[] = "<strong>$v</strong>";
    } else {
        $sortby_html[] = "<a href=\"index.php?sortby=$k\">$v</a>";
    }

}   

$sortby_htmo = implode(" | ", $sortby_html);







function make_thumbnail($updir, $img){
global $thumb_width, $thumb_height;

$thumbnail_width    = $thumb_width ? $thumb_width : 120;
$thumbnail_height   = $thumb_height ? $thumb_height : 80;

$arr_image_details  = GetImageSize("$updir"."$img");
$original_width     = $arr_image_details[0];
$original_height    = $arr_image_details[1];

if( $original_width > $original_height ){
    $new_width  = $thumbnail_width;
    $new_height = intval($original_height*$new_width/$original_width);
} else {
    $new_height = $thumbnail_height;
    $new_width  = intval($original_width*$new_height/$original_height);
}

$dest_x = intval(($thumbnail_width - $new_width) / 2);
$dest_y = intval(($thumbnail_height - $new_height) / 2);



if($arr_image_details[2]==1) { $imgt = "ImageGIF"; $imgcreatefrom = "ImageCreateFromGIF"; $imgx = "gif"; }
if($arr_image_details[2]==2) { $imgt = "ImageJPEG"; $imgcreatefrom = "ImageCreateFromJPEG"; $imgx = "jpeg"; }
if($arr_image_details[2]==3) { $imgt = "ImagePNG"; $imgcreatefrom = "ImageCreateFromPNG";  $imgx = "png"; }


if( $imgt ) { 
    $old_image  = $imgcreatefrom("$updir"."$img");
    $new_image  = ImageCreateTrueColor($thumbnail_width, $thumbnail_height);
    imageCopyResized($new_image,$old_image,$dest_x,         
    $dest_y,0,0,$new_width,$new_height,$original_width,$original_height);


    header("Content-Type: image/jpeg"); imagejpeg($new_image, NULL, 80);
}

}

if($_GET['thumb']) { 
 if( in_array($_GET['thumb'], $img_arr) ) make_thumbnail("./", $_GET['thumb']); // against file inclusion
 exit(); 
}
?>

这是一个画廊生成器脚本,但它只向我显示与脚本位于同一目录中的图片,我如何修改它以允许其他脚本。我尝试了很多调整,但没有任何效果。

4

1 回答 1

0

当您尝试打开根目录时,几乎可以肯定是文件权限问题。

$od = opendir("./");

它将适用于脚本所在的目录,因为脚本将有权访问该目录。

我不建议授予 PHP 访问根文件夹的权限(即使仅在读取模式下),因为这是一个巨大的安全风险,因为理论上有人可以读取您的密码文件。

相反,您应该使用非根目录来保存要为其生成图库的图像,并且只授予其读取权限,即

mkdir /var/images
chmod a+r /var/images
于 2013-01-26T03:46:36.547 回答