📄 images.php
字号:
<?/************************************************************************* Title.........: Image Manager, draws the thumbnails and directies** Version.......: 1.01** Author........: Xiang Wei ZHUO <wei@zhuo.org>** Filename......: images.php** Last changed..: 8 Mar 2003 ** Notes.........: Configuration in config.inc.php Functions - create a new folder, - delete folder, - upload new image - use cached thumbnail views***********************************************************************/include 'config.inc.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.'/');}function do_upload($file, $dest_dir) { global $clearUploads; if(is_file($file['tmp_name'])) { //var_dump($file); echo "DIR:$dest_dir"; move_uploaded_file($file['tmp_name'], $dest_dir.$file['name']); chmod($dest_dir.$file['name'], 0666); } $clearUploads = true;}function delete_folder($folder) { global $BASE_DIR, $refresh_dirs; //var_dump($BASE_DIR); $del_folder = dir_name($BASE_DIR).$folder; //echo $del_folder; if(is_dir($del_folder) && num_files($del_folder) <= 0) { //echo $del_folder.'<br>'; rm_all_dir($del_folder); $refresh_dirs = true; }}function rm_all_dir($dir) { //$dir = dir_name($dir); //echo "OPEN:".$dir.'<Br>'; if(is_dir($dir)) { $d = @dir($dir); while (false !== ($entry = $d->read())) { //echo "#".$entry.'<br>'; if($entry != '.' && $entry != '..') { $node = $dir.'/'.$entry; //echo "NODE:".$node; if(is_file($node)) { //echo " - is file<br>"; unlink($node); } else if(is_dir($node)) { //echo " - is Dir<br>"; rm_all_dir($node); } } } $d->close(); rmdir($dir); } //echo "RM: $dir <br>";}function delete_file($file) { global $BASE_DIR; $del_image = dir_name($BASE_DIR).$file; $del_thumb = dir_name($del_image).'.'.basename($del_image); 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."<br>"; if(substr($entry,0,1) != '.') { $total++; } } $d->close(); } return $total;}function dirs($dir,$abs_path) { $d = dir($dir); //echo "Handle: ".$d->handle."<br>\n"; //echo "Path: ".$d->path."<br>\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."<br>\n"; $path['path'] = $dir.'/'.$entry; $path['name'] = $entry; $dirs[$entry] = $path; } } $d->close(); ksort($dirs); for($i=0; $i<count($dirs); $i++) { $name = key($dirs); $current_dir = $abs_path.'/'.$dirs[$name]['name']; echo ", \"$current_dir\"\n"; dirs($dirs[$name]['path'],$current_dir); next($dirs); }}function parse_size($size) { if($size < 1024) return $size.' btyes'; else if($size >= 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);?><td><table width="102" border="0" cellpadding="0" cellspacing="2"> <tr> <td align="center" class="imgBorder" onMouseOver="pviiClassNew(this,'imgBorderHover')" onMouseOut="pviiClassNew(this,'imgBorder')"> <a href="javascript:;" onClick="javascript:imageSelected('<? echo $img_url; ?>', <? echo $info[0];?>, <? echo $info[1]; ?>,'<? echo $file; ?>');"><img src="<? echo $thumb_image; ?>" alt="<? echo $file; ?> - <? echo $filesize; ?>" border="0"></a></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="javascript:;" onClick="javascript:preview('<? echo $img_url; ?>', '<? echo $file; ?>', ' <? echo $filesize; ?>',<? echo $info[0].','.$info[1]; ?>);"><img src="edit_pencil.gif" width="15" height="15" border="0"></a></td> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="images.php?delFile=<? echo $img_url; ?>&dir=<? echo $newPath; ?>" onClick="return deleteImage('<? echo $file; ?>');"><img src="edit_trash.gif" width="15" height="15" border="0"></a></td> <td width="98%" class="imgCaption"><? echo $info[0].'x'.$info[1]; ?></td> </tr> </table></td> </tr></table></td><?}function show_dir($path, $dir) { global $newPath, $BASE_DIR, $BASE_URL; $num_files = num_files($BASE_DIR.$path);?><td><table width="102" border="0" cellpadding="0" cellspacing="2"> <tr> <td align="center" class="imgBorder" onMouseOver="pviiClassNew(this,'imgBorderHover')" onMouseOut="pviiClassNew(this,'imgBorder')"> <a href="images.php?dir=<? echo $path; ?>" onClick="changeLoadingStatus('load')"> <img src="folder.gif" width="80" height="80" border=0 alt="<? echo $dir; ?>"> </a> </td> </tr> <tr> <td><table width="100%" border="0" cellspacing="1" cellpadding="2"> <tr> <td width="1%" class="buttonOut" onMouseOver="pviiClassNew(this,'buttonHover')" onMouseOut="pviiClassNew(this,'buttonOut')"> <a href="images.php?delFolder=<? echo $BASE_URL.$path; ?>&dir=<? echo $newPath; ?>" onClick="return deleteFolder('<? echo $dir; ?>', <? echo $num_files; ?>);"><img src="edit_trash.gif" width="15" height="15" border="0"></a></td> <td width="99%" class="imgCaption"><? echo $dir; ?></td> </tr> </table></td> </tr></table></td><? }function draw_no_results() {?><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><div align="center" style="font-size:large;font-weight:bold;color:#CCCCCC;font-family: Helvetica, sans-serif;">No Images Found</div></td> </tr></table><? }function draw_no_dir() { global $BASE_DIR, $BASE_ROOT;?><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td><div align="center" style="font-size:small;font-weight:bold;color:#CC0000;font-family: Helvetica, sans-serif;">Configuration Problem: "<? echo $BASE_DIR.$BASE_ROOT; ?>" does not exist.</div></td> </tr></table><? }function draw_table_header() { echo '<table border="0" cellpadding="0" cellspacing="2">'; echo '<tr>';}function draw_table_footer() { echo '</tr>';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -