📄 filemanager.php
字号:
<?php////!!! getimagesize is not good enough alone... php code could be hidden inside!// I'd like to just put everything in a database though.. I just need to be able to find the mime-type..//defined('WikyBlog') or die("Not an entry point...");//---------------------// set default//---------------------global $page,$pageOwner,$dbObject,$lang;$page->displayTitle = $lang['image_manager'];if( !isOwner(true,false) ) return false;$dbObject->links[$lang['image_manager']] = '/Special/'.$pageOwner['username'].'/Image_Manager';$dbObject->links[$lang['file_manager']] = '/Special/'.$pageOwner['username'].'/File_Manager';$dbObject->links[$lang['file_upload']] = '/Special/'.$pageOwner['username'].'/File_Upload';$dbObject->links['?'] = $lang['image_manager'];class fileManager{ var $path; var $imgs=array(); var $checked = false; var $totals = array(); var $type = 'files'; function fileManager(){ global $lang,$page,$rootDir,$pageOwner,$dbObject; //image extensions $this->imgs['bmp'] = 1; $this->imgs['gif'] = 1; $this->imgs['jpe'] = 1; $this->imgs['jpeg'] = 1; $this->imgs['jfif'] = 1; $this->imgs['jpg'] = 1; $this->imgs['pic'] = 1; $this->imgs['png'] = 1; $this->imgs['tga'] = 1; $this->imgs['tif'] = 1; $this->imgs['tiff'] = 1; //these file formats will not be zipped before saving to file $this->safe['7z'] = 1; $this->safe['bz2'] = 1; $this->safe['gz'] = 1; $this->safe['gzip'] = 1; $this->safe['tar'] = 1; $this->safe['zip'] = 1; //in case there's a problem with $lang $lang += array('delete'=>'delete','confirm_delete'=>'confirm delete','upload'=>'upload'); $this->path = $rootDir.'/userfiles/'.toStorage($pageOwner['username'],true).'/uploaded'; switch($dbObject->title){ case 'fileupload': $this->uploadFile(); return; case 'imagemanager': $this->type = 'imgs'; break; } switch($page->userCmd){ case 'view': $this->viewFile(); break; case 'delete': //needed for links case wbStrtolower($lang['delete']): $this->deleteFile(); break; case wbStrtolower($lang['confirm_delete']): $this->confirmDelete(); break; case 'rename': $this->renameAction(); break; default: if( $this->type =='files'){ $this->showFiles(); }else{ $this->showImages(); } break; } } function renameAction(){ global $lang,$page,$dbObject,$pageOwner; $page->displayTitle = $lang['rename']; $dbObject->links[$lang['rename']] = '/Special/'.$pageOwner['username'].'/Image_Manager?cmd=rename&from='.$_GET['from'].'&to='.$_GET['to']; $isImage = true; if( empty($_GET['from']) ){ message('INVALID_REQUEST'); return; } if( empty($_GET['to']) ){ message('INVALID_REQUEST'); return; } $_GET['to'] = str_replace('\\','/',$_GET['to']); $_GET['from'] = str_replace('\\','/',$_GET['from']); if( strpos($_GET['to'],'/') !== false){ message('INVALID_REQUEST'); return; } if( strpos($_GET['from'],'/') !== false){ message('INVALID_REQUEST'); return; } $fromLocation = $this->path.'/'.$_GET['from']; $toLocation = $this->path.'/'.$_GET['to']; if( !file_exists($fromLocation) || !file_exists($toLocation) ){ message('INVALID_REQUEST'); return; } // // File Type // $fromParts = explode('.',$_GET['from']); $fromType = array_pop($fromParts); $fromType = strtolower($fromType); $toParts=explode('.',$_GET['to']); $toType = array_pop($toParts); $toType = strtolower($toType); if( $fromType !== $toType){ message('INVALID_REQUEST'); return; } wbData::loadFileFunctions(); ob_start(); echo '<div style="text-align:center;margin:4em;">'; wbUnlink($toLocation); if( renameFile($fromLocation,$toLocation) ){ echo $lang['RENAMED']; } echo '</div>'; $page->contentA[$lang['rename']] = wb::get_clean(); } function deleteFile(){ global $page,$dbObject,$pageOwner,$lang; $file =& $_GET['fName']; $fPath = $this->path.'/'.$file; if( !is_file($fPath) ){ message('FILE_DELETED'); return; } $dbObject->links[$file] = '/Special/'.$pageOwner['username'].'/Image_Manager?cmd=view&fName='.$file; $page->formAction = $dbObject->links[$file]; $t =& $page->contentA[$file]; $t .= '<div style="text-align:center;margin:4em;"><p>'; $t .= wbLang::text('CONFIRM_FILE_DELETE',$file); $t .= '</p><p>'; $t .= '<input type="submit" name="cmd['.htmlspecialchars($file).']" value="'.$lang['confirm_delete'].'" />'; $t .= '</p>'; $t .= '</div>'; } function confirmDelete(){ global $page,$pageOwner,$dbObject,$lang; $mess = ''; $dbObject->links[$page->cmdArg[0]] = '/Special/'.$pageOwner['username'].'/Image_Manager?cmd=view&fName='.$page->cmdArg[0]; $page->formAction = $dbObject->links[$page->cmdArg[0]]; $fPath = $this->path.'/'.$page->cmdArg[0]; //just a simple check here cause the queries should be coming directly from software if( strpos($fPath,'../') !== false){ message('INVALID_PATH',$fPath); return; } if( !is_file($fPath) ){ message('FILE_DELETED'); return; } $size = @filesize( $fPath ); if( !$size ){ message('FILE_DELETED'); return; } wbData::loadFileFunctions(); if( wbUnlink($fPath) ){ $mess = wbLang::text('IMAGE_DELETED',$page->cmdArg[0]); $pageOwner['disk_usage'] -= $size; }else{ $mess = wbLang::text('IMAGE_NOT_DELETED',$page->cmdArg[0]); } if( isset($pageOwner['imgs'][$page->cmdArg[0]])){ unset($pageOwner['imgs'][$page->cmdArg[0]]); }elseif( isset($pageOwner['files'][$page->cmdArg[0]])){ unset($pageOwner['files'][$page->cmdArg[0]]); } $page->contentA[$page->cmdArg[0]] = '<div style="text-align:center;margin:4em;">'.$mess.'</div>'; } function showImages(){ global $lang, $page,$pageOwner,$jsNum,$dbObject; $page->scripts[] = '/include/'.$jsNum.'/fileManager.js'; $page->formAction = $dbObject->links[$lang['image_manager']]; ob_start(); echo $lang['IMAGE_MANAGER_INTRO']; echo '<ul><li>[[image:<i>example.jpg</i>]]</li>'; echo '<li><img src="'.wbLinks::getDir('/userfiles/'.wbStrtolower($pageOwner['username'])).'/uploaded/<i>example.jpg</i>" height="113" width="150" /></li>'; echo '</ul>'; if( !isset($pageOwner['imgs']) ){ $temp = array(); $this->showManager($temp); }else{ $this->showManager($pageOwner['imgs']); } $page->contentA[$lang['image_manager']] = wb::get_clean(); } function showFiles(){ global $lang, $page,$pageOwner,$dbObject; $page->formAction = $dbObject->links[$lang['file_manager']]; $page->displayTitle = $lang['file_manager']; ob_start(); echo $lang['FILE_MANAGER_INTRO']; echo '<ul><li>[[attach:<i>example.doc.gz</i>]]</li>'; echo '<li><a href="'.wbLinks::getDir('/userfiles/'.wbStrtolower($pageOwner['username'])).'/uploaded/<i>example.doc.gz</i>" >Attachment<a></li>'; echo '</ul>'; if( !isset($pageOwner['files']) ){ $temp = array(); $this->showManager($temp); }else{ $this->showManager($pageOwner['files']); } $page->contentA[$lang['file_manager']] = wb::get_clean(); } function showManager(&$array){ global $page,$maxUserDiskUsage,$pageOwner,$lang; echo '<p><table cellpadding="4" cellspacing="0" width="100%" class="tableRows">'; $tableHeader = '<tr><th colspan="2">'.$lang['file_name'].'</th><th>'.$lang['size'].' ('.$lang['bytes'].')</th><th>'.$lang['modified'].'</th><th>'.$lang['options'].'</th></tr>'; $this->totals = array(); $this->totals['number']=0; $this->totals['size']=0; $this->checkPageOwner(); if( is_array($array)){ foreach($array as $file => $HxW){ if($this->totals['number']%14 == 0){ echo $tableHeader; } echo $this->managerRow($file); } } if($this->totals['number'] == 0 ){ echo '<tr><td></td><td>'.$lang['empty'].'</td><td>-</td><td>-</td></tr>'; } echo '<tr>'; echo '<td colspan="2">'.$lang['total'].'</td>'; echo '<td>'; echo number_format($this->totals['size']/1000,2).' '.$lang['kb'].' ('; echo number_format($this->totals['size']).' '.$lang['bytes'].')'; echo '</td>'; echo '</tr>'; echo '</table>'; //Totals echo '<p><table cellpadding="4" cellspacing="0" width="100%" class="tableRows" border="0">'; echo '<tr><th>'.$lang['total'].'</th><th>'.$lang['count'].'</th><th>'.$lang['total_size'].'</th><th>'.$lang['available_space'].'</th></tr>'; if( $this->type == 'files'){ $imgUsage = $pageOwner['disk_usage']-$this->totals['size']; $fileUsage = $this->totals['size']; }else{ $imgUsage = $this->totals['size']; $fileUsage = $pageOwner['disk_usage']-$this->totals['size']; } //something is wrong, recheck the values if( ($imgUsage < 0) || ($fileUsage < 0 )){ $this->checkPageOwner(true); } $all = 0; echo '<tr>'; echo '<td>'; echo $lang['images']; echo '</td><td>'; if( is_array($pageOwner['imgs']) ){ echo count($pageOwner['imgs']); $all += count($pageOwner['imgs']); }else{ echo '0'; } echo '</td>'; echo '<td>'; echo number_format($imgUsage/1000,2).' '.$lang['kb'].' ('; echo number_format($imgUsage).' '.$lang['bytes'].')'; echo '</td>'; echo '<td>-</td>'; echo '</tr>'; echo '<tr>'; echo '<td>'; echo $lang['files']; echo '</td><td>'; if( isset($pageOwner['files']) && is_array($pageOwner['files']) ){ echo count($pageOwner['files']); $all += count($pageOwner['files']); }else{ echo '0'; } echo '</td>'; echo '<td>'; echo number_format($fileUsage/1000,2).' '.$lang['kb'].' ('; echo number_format($fileUsage).' '.$lang['bytes'].')'; echo '</td>'; echo '<td>-</td>'; echo '</tr>'; echo '<tr>'; echo '<td>'.$lang['all'].'</td>'; echo '<td>'.$all.'</td>'; echo '<td>'; if( isset($pageOwner['disk_usage']) ){ $usage = $pageOwner['disk_usage']; }else{ $usage = 0; } echo number_format($usage/1000,2).' '.$lang['kb'].' ('; echo number_format($usage).' '.$lang['bytes'].')'; echo '</td>'; echo '<td>'; echo number_format( ($maxUserDiskUsage-$usage)/1000,2 ).' '.$lang['kb'].' ('; echo number_format($maxUserDiskUsage-$usage).' '.$lang['bytes'].')</td><td> </td>'; echo '</tr>'; echo '<td> </td>'; echo '</tr>'; echo '</table>'; } function managerRow($fName){ global $page,$dbObject,$lang,$pageOwner; $isImage = false; /// Make Sure It's still there $fullPath = $this->path.'/'.$fName; if( !is_file($fullPath)){ if( isset($pageOwner['imgs'][$fName]) ){ unset($pageOwner['imgs'][$fName]); } return; } /// If Image if( isset($pageOwner['imgs'][$fName]) ){ list($imgX,$imgY) = wbExplode('x',$pageOwner['imgs'][$fName]); $isImage = true; } /// Get File Info if $stats = stat($this->path.'/'.$fName); $this->totals['number']++; $this->totals['size']+=$stats['size']; if($this->totals['number']%2 == 1){ $class = ' class="tableRowOdd" '; }else{ $class = ' class="tableRowEven" '; } /// Output Text echo '<tr '.$class.'><td class="sm">'.$this->totals['number'].'</td>'; echo '<td>'. $fName.'</td>'; echo '<td>' . number_format($stats['size']) .'</td>'; echo '<td>'.date("F j, Y, g:i a" ,$stats['mtime']).'</td>'; echo '<td>'; echo '<div class="sm">'; if( $isImage && isset($imgX) ){ echo wbLinks::local($dbObject->links[$lang['image_manager']].'?cmd=view&fName='.$fName,$lang['view'],' onclick="showImage(event,\''.addslashes($fName).'\','.$imgY.','.$imgX.')"'); }else{ echo '<a href="'.wbLinks::getDir('/userfiles/'.wbStrtolower($pageOwner['username'])).'/uploaded/'.$fName.'" target="_new" >'.$lang['view'].'</a>'; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -