* * Modified for eGW by and (c) by Pim Snel * * -------------------------------------------- * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; version 2 of the License. * * -------------------------------------------- * * Title.........: Image Manager, draws the thumbnails and directies * * Version.......: 1.01 * * Author........: Xiang Wei ZHUO * * Notes.........: Configuration in config.inc.php * * * * Functions * * - create a new folder, * * - delete folder, * * - upload new image * * - use cached thumbnail views * \**************************************************************************/ /* $id */ // FIXME move all php functions to a main file // FIXME better directory-structure include 'config.inc.php'; require_once 'std_functions.inc.php'; require_once '../ImageEditor/Transform.php'; if(isset($_GET['dir'])) { $dirParam = $_GET['dir']; if(strlen($dirParam) > 0) { if(substr($dirParam,0,1)=='/') $IMG_ROOT .= $dirParam; else $IMG_ROOT = $dirParam; } } $refresh_dirs = false; $clearUploads = false; if(strrpos($IMG_ROOT, '/')!= strlen($IMG_ROOT)-1) $IMG_ROOT .= '/'; if(isset($_GET['create']) && isset($_GET['dir']) && $SAFE_MODE == false) { create_folder(); } if(isset($_GET['delFile']) && isset($_GET['dir'])) { delete_file($_GET['delFile']); } if(isset($_GET['delFolder']) && isset($_GET['dir'])) { delete_folder($_GET['delFolder']); } if(isset($_FILES['upload']) && is_array($_FILES['upload']) && isset($_POST['dirPath'])) { $dirPathPost = $_POST['dirPath']; if(strlen($dirPathPost) > 0) { if(substr($dirPathPost,0,1)=='/') $IMG_ROOT .= $dirPathPost; else $IMG_ROOT = $dirPathPost; } if(strrpos($IMG_ROOT, '/')!= strlen($IMG_ROOT)-1) $IMG_ROOT .= '/'; // do_upload($_FILES['upload'], $BASE_DIR.$BASE_ROOT.$dirPathPost.'/'); do_upload($_FILES['upload'], $BASE_DIR.$dirPathPost.'/'); } function do_upload($file, $dest_dir) { global $clearUploads,$MAX_WIDTH,$MAX_HEIGHT; if(is_file($file['tmp_name'])) { $img_info = getimagesize($file['tmp_name']); //_debug_array($img_info); if(is_array($img_info)) { $w = $img_info[0]; $h = $img_info[1]; if( $w > $MAX_WIDTH || $h > $MAX_HEIGHT ) { adapt_size($file['tmp_name'],$dest_dir.$file['name']); } else { move_uploaded_file($file['tmp_name'], $dest_dir.$file['name']); } chmod($dest_dir.$file['name'], 0666); } } $clearUploads = true; } function adapt_size($img,$dest_file) { global $BASE_DIR, $BASE_URL,$MAX_WIDTH,$MAX_HEIGHT; $path_info = pathinfo($img); $path = $path_info['dirname']."/"; $img_file = $path_info['basename']; $img_info = getimagesize($path.$img_file); $w = $img_info[0]; $h = $img_info[1]; $nw = $MAX_WIDTH; $nh = $MAX_HEIGHT; $img_resize = Image_Transform::factory(IMAGE_CLASS); $img_resize->load($path.$img_file); if ($w > $h) $nh = unpercent(percent($nw, $w), $h); else if ($h > $w) $nw = unpercent(percent($nh, $h), $w); $img_resize->resize($nw, $nh); $img_resize->save($dest_file); $img_resize->free(); chmod($dest_file, 0666); } function delete_folder($folder) { global $BASE_DIR, $refresh_dirs; $del_folder = dir_name($BASE_DIR).$folder; if(is_dir($del_folder) && num_files($del_folder) <= 0) { rm_all_dir($del_folder); $refresh_dirs = true; } } function rm_all_dir($dir) { //$dir = dir_name($dir); //echo "OPEN:".$dir.'
'; if(is_dir($dir)) { $d = @dir($dir); while (false !== ($entry = $d->read())) { //echo "#".$entry.'
'; if($entry != '.' && $entry != '..') { $node = $dir.'/'.$entry; //echo "NODE:".$node; if(is_file($node)) { //echo " - is file
"; unlink($node); } else if(is_dir($node)) { //echo " - is Dir
"; rm_all_dir($node); } } } $d->close(); rmdir($dir); } //echo "RM: $dir
"; } function delete_file($file) { global $BASE_DIR,$IMG_ROOT; $del_image = dir_name($BASE_DIR).$IMG_ROOT.$file; $del_thumb = dir_name($BASE_DIR).$IMG_ROOT.$file; if(is_file($del_image)) { unlink($del_image); } if(is_file($del_thumb)) { unlink($del_thumb); } } function create_folder() { global $BASE_DIR, $IMG_ROOT, $refresh_dirs; $folder_name = $_GET['foldername']; if(strlen($folder_name) >0) { $folder = $BASE_DIR.$IMG_ROOT.$folder_name; if(!is_dir($folder) && !is_file($folder)) { mkdir($folder,0777); chmod($folder,0777); $refresh_dirs = true; } } } function num_files($dir) { $total = 0; if(is_dir($dir)) { $d = @dir($dir); while (false !== ($entry = $d->read())) { //echo $entry."
"; if(substr($entry,0,1) != '.') { $total++; } } $d->close(); } return $total; } function dirs($dir,$abs_path) { $d = dir($dir); //echo "Handle: ".$d->handle."
\n"; //echo "Path: ".$d->path."
\n"; $dirs = array(); while (false !== ($entry = $d->read())) { if(is_dir($dir.'/'.$entry) && substr($entry,0,1) != '.') { //dirs($dir.'/'.$entry, $prefix.$prefix); //echo $prefix.$entry."
\n"; $path['path'] = $dir.'/'.$entry; $path['name'] = $entry; $dirs[$entry] = $path; } } $d->close(); ksort($dirs); for($i=0; $i= 1024 && $size < 1024*1024) { return sprintf('%01.2f',$size/1024.0).' Kb'; } else { return sprintf('%01.2f',$size/(1024.0*1024)).' Mb'; } } function show_image($img, $file, $info, $size) { global $BASE_DIR, $BASE_URL, $newPath; $img_path = dir_name($img); $img_file = basename($img); $thumb_image = 'thumbs.php?img='.urlencode($img); $img_url = $BASE_URL.$img_path.'/'.$img_file; $filesize = parse_size($size); ?>
<? echo $file; ?> - <? echo $filesize; ?>
<? echo $dir; ?>
No Images Found
Configuration Problem: "" does not exist.
'; echo ''; } function draw_table_footer() { echo ''; echo ''; } ?> Image Browser 0) { $upDirPath .= $path.'/'; } } $slashIndex = strlen($dirPath); $newPath = $dirPath; if($slashIndex > 1 && substr($dirPath, $slashIndex-1, $slashIndex) == '/') { $newPath = substr($dirPath, 0,$slashIndex-1); } ?> '; $d = @dir($BASE_DIR.$IMG_ROOT); if($d) { //var_dump($d); $images = array(); $folders = array(); while (false !== ($entry = $d->read())) { $img_file = $IMG_ROOT.$entry; if(is_file($BASE_DIR.$img_file) && substr($entry,0,1) != '.') { $image_info = @getimagesize($BASE_DIR.$img_file); if(is_array($image_info)) { $file_details['file'] = $img_file; $file_details['img_info'] = $image_info; $file_details['size'] = filesize($BASE_DIR.$img_file); $images[$entry] = $file_details; //show_image($img_file, $entry, $image_info); } } else if(is_dir($BASE_DIR.$img_file) && substr($entry,0,1) != '.') { $folders[$entry] = $img_file; //show_dir($img_file, $entry); } } $d->close(); if(count($images) > 0 || count($folders) > 0) { //now sort the folders and images by name. ksort($images); ksort($folders); draw_table_header(); for($i=0; $i