...

View Full Version : how to deal with permission in terminal on Mac



begeiste
11-26-2007, 09:14 PM
Hi,
A error shows when I clicked on my gallery greek directory at http://localhost/gallery/index.php, I've got this error as following(permission issue):
Warning: opendir(./images/greek/) [function.opendir]: failed to open dir: Permission denied in /Library/WebServer/gallery/index.php on line 405

Warning: readdir(): supplied argument is not a valid Directory resource in /Library/WebServer/gallery/index.php on line 408

I am not sure how to fix this permission issue in terminal.
<?


// ----------- Constants are below ------------

define(GALLERY_ROOT, "./images/");
define(THUMB_ROOT, "./thumbs/");
define(SAVE_THUMBS, TRUE);
define(GALLERY_NAME, "ABC Familymedianet Photos Promotion");
$home_text = "Home";
$gallery_header = "Gallery";
$sub_gallery_header = "Sub Galleries";
$split_dir_img = TRUE;
define(THUMB_MAX_WIDTH, 160);
define(THUMB_MAX_HEIGHT, 160);
$table_border_width = 1;
$thumb_border_width = 1;
$thumb_td_padding = 7;
$thumb_td_spacing = 15;
$thumb_td_border_width = 1;
define(HIGH_QUALITY_THUMB, TRUE);
$dir_underscore_as_space = TRUE;
$image_in_new_window = TRUE;
$click_image = "- Click image to close window -";
$window_extra_width = 80;
$window_extra_height = 133;
$text_height = 16;
$scrollbar_width = 17;
$use_java = TRUE;
$show_image_name = TRUE;
$show_dir_name = TRUE;
$show_alt_description = TRUE;
$gallery_description_file = "_desc.txt";
$gallery_name_file = "_name.txt";
$gallery_columns = 4;
$sort_divider = "--";
$color_body_back = "#202020";
$color_body_text = "#ffffff";
$color_link = "#ffffff";
$color_link_hover = "#f27b08";
$color_thumb_border = "#ffffff";
$color_thumb_td_border = "#505050";
$color_thumb_td = "#303030";
$color_dir_thumb_border = "#ffffff";
$color_dir_thumb_td_border = "#505050";
$color_dir_thumb_td = "#000000";
$color_table_back = "#000000";
$color_table_text = "#ffffff";
$color_table_border = "#505050";
$color_table_header = "#505050";
$color_table_header_text = "#ffffff";
$color_table_sub_header = "#505050";
$color_table_sub_header_text = "#ffffff";
$color_table_desc = "#363636";
$color_table_desc_text = "#ffffff";

// --------------------------------------

// functions are listing below

function print_doc_start($head="", $body="") {
echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"".$_SERVER[PHP_SELF]."?cmd=css\"><meta http-equiv=\"Content-Type\" content=\"text/html;charset=utf-8\"><title>".htmlentities(GALLERY_NAME)."</title>".$head."</head><body".$body.">";
}


function print_doc_end() {
echo "</body></html>";
}


function makedir($path) {
$dirs=array();
$dirs=explode("/",$path);
$path=THUMB_ROOT;
foreach ($dirs as $element) {
$path.=$element."/";
if(!is_dir($path)) {
mkdir($path);
}
}
}


function image_type_ok($file) {
$type = strtolower(substr($file, strrpos($file, ".")));
if ($type==".jpg" or $type==".jpeg") {
return TRUE;
} else {
return FALSE;
}
}


function file_ok($file) {
if (!image_type_ok($file)) { return FALSE; }
if (!file_exists($file)) { return FALSE; }
return TRUE;
}


function print_thumb($image_dir, $image_file) {
if (THUMB_ROOT!="") {
$thumb_file = THUMB_ROOT.$image_dir.$image_file;
} else {
$thumb_file = "";
}
if(file_ok($thumb_file)) {
$file_pointer=fopen($thumb_file, "rb");
header("Content-type: image/jpeg");
fpassthru($file_pointer);
fflush();
} else {
if(image_type_ok($image_file)) {
if (!$image = imagecreatefromjpeg(GALLERY_ROOT.$image_dir.$image_file)) {
exit;
}
} else {
exit;
}
$image_size = getimagesize(GALLERY_ROOT.$image_dir.$image_file);
$image_width = $image_size[0];
$image_height = $image_size[1];
$aspect_x = $image_width / THUMB_MAX_WIDTH;
$aspect_y = $image_height / THUMB_MAX_HEIGHT;
if ($aspect_x > $aspect_y) {
$thumb_width = THUMB_MAX_WIDTH;
$thumb_height = $image_height / $aspect_x;
} else {
$thumb_height = THUMB_MAX_HEIGHT;
$thumb_width = $image_width / $aspect_y;
}
$thumb = @imagecreatetruecolor($thumb_width, $thumb_height);
if (HIGH_QUALITY_THUMB) {
imagecopyresampled($thumb,$image,0,0,0,0,$thumb_width,$thumb_height,imagesx($image),imagesy($image)) ;
} else {
imagecopyresized($thumb,$image,0,0,0,0,$thumb_width,$thumb_height,imagesx($image),imagesy($image));
}
imagedestroy($image);
if (SAVE_THUMBS and (THUMB_ROOT!="")) {
if (!is_dir(THUMB_ROOT.$image_dir)) {
makedir($image_dir);
}
imagejpeg($thumb, $thumb_file);
}
header("Content-type: image/jpeg");
imagejpeg($thumb);
imagedestroy($thumb);
}
}


function get_file($file_to_print, $only_first_line=FALSE, $br_for_new_line=TRUE) {
if ($lines = @file($file_to_print)) {
reset($lines);
if ($only_first_line) {
return htmlentities($lines[0]);
} else {
$result="";
while (list($key, $line) = each($lines)) {
$result.=($result!="" ? ($br_for_new_line ? "<br>" : "") : "").htmlentities($line);
}
}
} else {
return "";
}
return $result;
}


function get_first_image($image_dir) {
$directory_handle = opendir(GALLERY_ROOT.$image_dir);
$dirs = array();
$files = array();
while($var = readdir($directory_handle)) {
if (is_dir(GALLERY_ROOT.$image_dir.$var) and $var!="." and $var!="..") {
$dirs[] = $var;
} elseif (!is_dir(GALLERY_ROOT.$image_dir.$var) and (image_type_ok($var)) ) {
$files[] = $var;
}
}
sort ($dirs);
reset ($dirs);
sort ($files);
reset ($files);
if (isset($files[0])) {
$result = array("dir"=>$image_dir, "file"=>$files[0]);
return $result;
} else {
foreach ($dirs as $subdir) {
$subresult = get_first_image($image_dir.$subdir."/");
if (isset($subresult[file])) {
return $subresult;
}
}
}
}


function repeat_string($str, $times) {
for ($i=1; $i<=$times; $i++) {
echo $str;
}
}


if ($_GET[cmd]=="css") {
header("Content-type: text/css");
echo "
body {
background : $color_body_back;
color: $color_body_text;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-weight: normal;
text-align : center;
margin : 15px;
}

a:active,a:link,a:visited,a:focus {
color: $color_link;
font-weight: normal;
text-decoration : none;
}

a:hover {
color : $color_link_hover;
}

small {
font-size: 10px;
font-weight: normal;

}

table.outer {
border : ".$table_border_width."px solid $color_table_border;
background : $color_table_back;
color: $color_table_text;
font-size: 14px;
text-align : center;
vertical-align : top;
margin : 0px;
padding : 0px;
margin-left:auto;
margin-right:auto;
}

table.outer td {
border : none;
color: $color_table_text;
padding : 5px;
}

table.outer td.img {
border : ".$thumb_td_border_width."px solid $color_thumb_td_border;
background : $color_thumb_td;
padding : ".$thumb_td_padding."px;
}

table.outer td.dir {
border : ".$thumb_td_border_width."px solid $color_dir_thumb_td_border;
background : $color_dir_thumb_td;
padding : ".$thumb_td_padding."px;
}

table.outer td.empty {
border : none;
background : $color_table_back;
padding : 0px;
}

table.outer td.desc {
background : $color_table_desc;
color: $color_table_desc_text;
}

table.outer th {
border : none;
background : $color_table_header;
color: $color_table_header_text;
font-size: 18px;
font-weight: bold;
text-align : center;
padding : 5px;
}

table.outer th.sub {
border : none;
background : $color_table_sub_header;
color: $color_table_sub_header_text;
font-size: 14px;
font-weight: normal;
text-align : left;
padding : 1px 1px 1px 10px;
}

img.dir {
border : ".$thumb_border_width."px solid $color_dir_thumb_border;
margin : 0px;
}

img.thumb {
border : ".$thumb_border_width."px solid $color_thumb_border;
margin : 0px;


}

img.full {
border: none;
margin : 10px;
}
";
exit;
}


$gallery = trim($_GET[gallery]);
$image = trim($_GET[image]);
if(strpos($gallery.$image, "..")!==FALSE) {
exit("Gallery and/or Image is not accessible!");
}


if ($_GET[cmd]=="thumb") {
print_thumb($gallery, $image);
exit;
}


if ($_GET[cmd]=="dirthumb") {
$first_image = get_first_image($gallery);
print_thumb($first_image[dir], $first_image[file]);
exit;
}


if ($_GET[cmd]=="imageform") {
$image_file=GALLERY_ROOT.$gallery.$image;
$description_file = substr($image_file, 0, strrpos($image_file, ".")).".txt";
$desc = get_file($description_file);
$text_space = substr_count(strtolower($desc), "<br>") * $text_height;
if ($desc) {
$text_space += $text_height;
}
if ($click_image != "") {
$text_space += $text_height;
}
if ($use_java and $image_in_new_window) {
$add_to_head ="<script language=\"JavaScript\" TYPE=\"text/javascript\">
<!--
function windowchange() {
var posx,posy,width,height;
self.focus();
if (document.images) {
width = document.images['fullimage'].width+".$window_extra_width.";
height = document.images['fullimage'].height+".($window_extra_height+$text_space).";
if (width > window.screen.availWidth) { width = window.screen.availWidth; height=height+".$scrollbar_width."; }
if (height > window.screen.availHeight) { height = window.screen.availHeight; width=width+".$scrollbar_width."; }
if (width > window.screen.availWidth) width = window.screen.availWidth;
posx = (window.screen.availWidth-width) / 2;
posy = (window.screen.availHeight-height) / 2;
window.moveTo(0,0);
window.resizeTo(width,height);
window.moveTo(posx,posy);
window.focus();
}
return true;
}
//-->
</script>";
} else {
$add_to_head ="";
}
print_doc_start($add_to_head, (($use_java and $image_in_new_window) ? " OnLoad=\"javascript:windowchange();\"" : ""));
if (!($image_in_new_window and !$use_java)) {
echo "<a href=\"".($image_in_new_window ? ($use_java ? "javascript:window.close()" : "") : ($use_java ? "javascript:history.go(-1)" : $_SERVER[PHP_SELF]."?gallery=".$gallery))."\">";
}
echo "<img id=\"fullimage\" alt=\"\" class=\"full\" src=\"".$_SERVER[PHP_SELF]."?cmd=image&amp;gallery=".$gallery."&amp;image=".$image."\">";
if ($click_image != "") {
echo "<br><small>".$click_image."</small>";
}
if (!($image_in_new_window and !$use_java)) {
echo "</a>";
}
if ($desc) {
echo "<br>".$desc;
}
print_doc_end();
exit;
}


if ($_GET[cmd]=="image") {
$image_file = GALLERY_ROOT.$gallery.$image;
if(file_ok($image_file)) {
$file_pointer=fopen($image_file, "rb");
header("Content-type: image/jpeg");
header("Content-Disposition: inline; filename=".$image);
fpassthru($file_pointer);
fflush();
}
exit;
}


if (!isset($_GET[cmd])) {
$directory_handle = opendir(GALLERY_ROOT.$gallery);
$dirs = array();
$files = array();
while($var = readdir($directory_handle)) {
if (is_dir(GALLERY_ROOT.$gallery.$var) and $var!="." and $var!="..") {
$dirs[] = $var;
} elseif (!is_dir(GALLERY_ROOT.$gallery.$var) and (image_type_ok($var)) ) {
$files[] = $var;
}
}
sort ($dirs);
reset ($dirs);
sort ($files);
reset ($files);
print_doc_start();

$total_columns=($gallery_columns*2)+1;
$img_width=THUMB_MAX_WIDTH+($thumb_border_width*2);
$img_td_width=$img_width+(($thumb_td_border_width+$thumb_td_padding)*2);
$table_width=(($img_td_width+$thumb_td_spacing)*$gallery_columns)+$thumb_td_spacing+($table_border_w idth*2);
$write_width = (($img_td_width+$thumb_td_spacing)*$gallery_columns)+$thumb_td_spacing-10;

$spacing_row="<tr><td class=\"empty\" colspan=".$total_columns." height=".$thumb_td_spacing."></td></tr>";
$spacing_col="<td class=\"empty\" width=".$thumb_td_spacing."></td>";
$empty_cell="<td class=\"empty\" width=".$img_td_width."></td>";

echo "<table class=\"outer\" cellspacing=0 width=".$table_width.">";
echo "<tr><th colspan=".$total_columns.">".htmlentities(GALLERY_NAME)."</th></tr>";
echo "<tr><td width=".$write_width." colspan=".$total_columns.">";
$links=explode("/", $gallery);
echo "[<a href=\"".$_SERVER[PHP_SELF]."\">".htmlentities($home_text)."</a>]";
if ($gallery!="" and is_array($links)) {
for ($i=0; $i<=sizeof($links)-1; $i++) {
if ($links[$i]!="") {
echo " -> [<a href=\"".$_SERVER[PHP_SELF]."?gallery=";
$gal_link="";
for ($u=0; $u<=$i; $u++) {
$gal_link.=$links[$u]."/";
}
echo $gal_link;
$name = get_file(GALLERY_ROOT.$gal_link.$gallery_name_file , TRUE);
if ($name) {
$display_name = $name;
} else {
$break_pos = strpos($links[$i], $sort_divider);
if ($break_pos != FALSE) {
$break_pos = $break_pos+strlen($sort_divider);
}
$display_name = substr($links[$i], $break_pos);
$display_name = ($dir_underscore_as_space ? str_replace("_", " ", $display_name) : $display_name);
}
echo"\">".$display_name."</a>]";
}
}
}
echo "</td></tr>";

$desc = get_file(GALLERY_ROOT.$gallery.$gallery_description_file);
if ($desc) {
echo "<tr><td width=".$write_width." class=\"desc\" colspan=".$total_columns.">";
echo $desc;
echo "</td></tr>";
}

if (!$split_dir_img) {
echo "<tr><th class=\"sub\" colspan=".$total_columns.">".htmlentities($gallery_header)."</th></tr>";
echo $spacing_row;
}

if (sizeof($dirs)>0) {
if ($split_dir_img) {
echo "<tr><th class=\"sub\" colspan=".$total_columns.">".htmlentities($sub_gallery_header)."</th></tr>";
echo $spacing_row;
}
echo "<tr>";
$cols=0;
for($x = 0; $x < sizeof($dirs); $x++) {
$cols++;
if($cols > $gallery_columns) {
echo $spacing_col;
echo "</tr>";
echo $spacing_row;
echo "<tr>";
$cols=1;
}
$name = get_file(GALLERY_ROOT.$gallery.$dirs[$x]."/".$gallery_name_file, TRUE);
if ($name) {
$display_name = $name;
} else {
$break_pos = strpos($dirs[$x], $sort_divider);
if ($break_pos != FALSE) {
$break_pos = $break_pos+strlen($sort_divider);
}
$display_name = substr($dirs[$x], $break_pos);
$display_name = ($dir_underscore_as_space ? str_replace("_", " ", $display_name) : $display_name);
}
echo $spacing_col;
echo "<td width=".$img_width." class=\"dir\"><a href=\"".$_SERVER[PHP_SELF]."?gallery=".$gallery.$dirs[$x]."/\"><img alt=\"".($show_alt_description ? get_file(GALLERY_ROOT.$gallery.$dirs[$x]."/".$gallery_description_file,FLASE,FALSE) : "")."\" class=\"dir\" src=\"".$_SERVER[PHP_SELF]."?cmd=dirthumb&amp;gallery=".$gallery.$dirs[$x]."/\">".($show_dir_name ? "<br>[".$display_name."]" : "")."</a></td>";
}
if ($split_dir_img) {
repeat_string($spacing_col.$empty_cell, ($gallery_columns-$cols));
echo $spacing_col;
echo "</tr>";
echo $spacing_row;
}
}

if (sizeof($files)>0) {
if ($split_dir_img) {
echo "<tr><th class=\"sub\" colspan=".$total_columns.">".htmlentities($gallery_header)."</th></tr>";
echo $spacing_row;
echo "<tr>";
$cols=0;
}
for($x = 0; $x < sizeof($files); $x++) {
$cols++;
if($cols > $gallery_columns) {
echo $spacing_col;
echo "</tr>";
echo $spacing_row;
echo "<tr>";
$cols=1;
}
$break_pos = strpos($files[$x], $sort_divider);
if ($break_pos != FALSE) {
$break_pos = $break_pos+strlen($sort_divider);
}
$display_name = substr($files[$x], $break_pos);
echo $spacing_col;
echo "<td width=".$img_width." class=\"img\">";
if ($use_java and $image_in_new_window) {
echo "<a href=\"javascript:void(null)\" onClick=\"javascript:window.open('".$_SERVER[PHP_SELF]."?cmd=imageform&amp;gallery=".$gallery."&amp;image=".$files[$x]."', '', 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes');\">";
} else {
echo "<a".($image_in_new_window ? " target=\"_blank\"" : "")." href=\"".$_SERVER[PHP_SELF]."?cmd=imageform&amp;gallery=".$gallery."&amp;image=".$files[$x]."\">";
}
echo "<img alt=\"".($show_alt_description ? get_file(substr(GALLERY_ROOT.$gallery.$files[$x], 0, strrpos(GALLERY_ROOT.$gallery.$files[$x], ".")).".txt",FALSE,FALSE) : "")."\" class=\"thumb\" src=\"".$_SERVER[PHP_SELF]."?cmd=thumb&amp;gallery=".$gallery."&amp;image=".$files[$x]."\">".($show_image_name ? "<br><small>".$display_name."</small>" : "")."</a></td>";
}
repeat_string($spacing_col.$empty_cell, ($gallery_columns-$cols));
echo $spacing_col;
echo "</tr>";
echo $spacing_row;
}

if (!(sizeof($files)>0) and !$split_dir_img) {
repeat_string($spacing_col.$empty_cell, ($gallery_columns-$cols));
echo $spacing_col;
echo "</tr>";
echo $spacing_row;
}

echo "</table>";
echo "<small><a target=\"_blank\" href=\"http://sye.dk/sfpg/\">sfpg 1.5.0 - sye.dk</a></small>";
print_doc_end();
exit;
}
?> I will be much appreciated your help!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum