📄 filemanager.php
字号:
echo ' '.wbLinks::special('Image_Manager?cmd=delete&fName='.urlencode($fName),'delete'); echo '</div>'; echo '</td></tr>'; } function uploadFile(){ global $page,$pageOwner,$lang, $maxUserDiskUsage, $max_upload, $jsNum; $page->formAction = '/Special/'.$pageOwner['username'].'/File_Upload'; $page->formEnc= 'multipart/form-data'; // set default $page->displayTitle = $lang['upload_files']; //Force the checkPageOwner for every 10 files uploaded.. $numFiles = 0; if( isset($pageOwner['imgs']) && is_array($pageOwner['imgs']) ){ $numFiles += count($pageOwner['imgs']); } if( isset($pageOwner['files']) && is_array($pageOwner['files']) ){ $numFiles += count($pageOwner['files']); } // set variables for the uploaded file if( !empty($_FILES['userfile'] ) ){ $this->checkPageOwner(); wbData::loadFileFunctions(); foreach($_FILES['userfile']['name'] as $key => $fName){ if( empty($fName) ){ continue; } if( !$this->uploadFile2($key) ){ continue; } $numFiles++; if( ($numFiles%10) === 0){ $this->checkPageOwner(true); } } } ob_start(); $page->scripts[] = '/include/'.$jsNum.'/fileUpload.js'; echo ' <br>'; echo '<table width="100%" border="0"><tr><td>'; echo '<tr><td>'; echo '<table width="100%" class="tableRows"><tbody id="files">'; echo '<tr>'; echo '<th colspan=2>File</th>'; echo '</tr>'; echo '<tr ><td style="text-align:right">'; echo '<input type="file" name="userfile[]" onchange="wbUL.addFile(this)" />'; echo '</td><td></tr>'; echo '<tr><td style="text-align:right">'; echo ' <label><span class="sm">'.$lang['overwrite_existing'].'</span> '; if( isset($_POST['overwrite']) ){ echo '<input type="checkbox" name="overwrite" value="true" checked="checked" />'; }else{ echo '<input type="checkbox" name="overwrite" value="true" />'; } echo '</label> '; echo '<input type="submit" name="cmd" value="'.$lang['upload'].'"/>'; echo '</td></tr></tbody></table>'; echo '</td>'; echo '<td rowspan="5">'; echo $lang['UPLOAD_INTRO'].'<br> '; echo '</td></tr>'; echo '<tr><td>'; echo '<input type="hidden" name="MAX_FILE_SIZE" value="'.$max_upload.'">'; echo '</td></tr></table>'; echo '<div id="wbUpFiles" style="display:none">'; if( isset($pageOwner['imgs']) ){ foreach($pageOwner['imgs'] as $file => $null){ echo '<span>'; echo $file; echo '</span>'; } } if( isset($pageOwner['files']) ){ foreach($pageOwner['files'] as $file => $null){ echo '<span>'; $temp=explode('.',$file); $file_type = array_pop($temp); $file_type = strtolower($file_type); if( $file_type == 'gz'){ echo substr($file,0,-3); }elseif( $file_type == 'bz2'){ echo substr($file,0,-4); }else{ echo $file; } echo '</span>'; } } echo '</div>'; $page->contentA[$lang['file_upload']] = wb::get_clean(); } function uploadFile2($i){ global $page, $maxUserDiskUsage, $max_upload, $pageOwner,$wbFTP; $data = false; $isImage = true; $exists = false; $diskUsage = $pageOwner['disk_usage']; $fName = $_FILES['userfile']['name'][$i]; $tempFullPath = $_FILES['userfile']['tmp_name'][$i]; $stats = stat($tempFullPath); $fileSize = $stats['size']; if( !isset($pageOwner['disk_usage']) ){ $pageOwner['disk_usage'] = 0; } // // File Type // $nameParts=explode('.',$fName); $file_type = array_pop($nameParts); $file_type = strtolower($file_type); if( !isset($this->imgs[$file_type]) ){ $isImage = false; // $html= array('htm'=>1,'html'=>1,'shtml'=>1); // if( isset($html[$file_type]) ){ // $fName = $fName.'.txt'; // } } // // Compression Type // $compressType = ''; if( !$isImage ){ if( function_exists('gzencode') ){ $compressType = '.gz'; }elseif( function_exists('bzcompress') ){ $compressType = '.bz2'; }else{ message('UPLOAD_FAILED',$fName); return false; } } // // Check for existing files // $destinationFile = $this->path.'/'.$fName.$compressType; if( !isset($_POST['overwrite']) && file_exists($destinationFile) ){ $exists = $fName; //reduce the diskUsage if the file is being overWritten.. $temp = stat($destinationFile); if( $temp ){ $diskUsage -= $temp['size']; } $tempName = implode('.',$nameParts); $i = 1; do{ $fName = $tempName.'_'.$i.'.'.$file_type; $destinationFile = $this->path.'/'.$fName.$compressType; $i++; }while(file_exists($destinationFile)); } if($fileSize > $max_upload){ message('CANNOT_UPLOAD_2',$fName,$max_upload); return false; } if( ($pageOwner['disk_usage'] + $fileSize) > $maxUserDiskUsage){ message('CANNOT_UPLOAD_3',$fName,number_format($pageOwner['disk_usage'])); return false; } if( !checkPath($this->path,'userfiles') ){ trigger_error('Invalid Directory 1'); return false; } if( !makeDir($this->path) ){ trigger_error('Couldnt make directory'); return false; } ////////////////////////////////////////////////////////////////// // // Save the file // //Image Upload if( $isImage ){ if( !wbMove_uploaded_file($tempFullPath, $destinationFile)) { message('UPLOAD_FAILED',$fName); return false; } //Compress File & save w/ FTP }elseif( isset($wbFTP) && isset($wbFTP['use']) && $wbFTP['use'] ){ $contents = file_get_contents($tempFullPath); if( $compressType == '.gz'){ $contents = gzencode($contents); }elseif( $compressType == '.bz2'){ $contents = bzcompress($contents); } if( !saveFile($destinationFile,$contents) ){ message('UPLOAD_FAILED',$fName); return false; } $pageOwner['files'][$fName.$compressType] = 1; //Compress File & save }else{ $contents = file_get_contents($tempFullPath); if( $compressType == '.gz'){ $handle = gzopen($destinationFile,'w5'); if( !$handle ){ message('UPLOAD_FAILED',$fName); return false; } if( !gzwrite($handle, $contents) ){ message('UPLOAD_FAILED',$fName); return false; } gzclose($handle); }elseif( $compressType == '.bz2'){ $handle = bzopen($destinationFile, 'w'); if( !$handle ){ message('UPLOAD_FAILED',$fName); return false; } if( !bzwrite($handle, $contents) ){ message('UPLOAD_FAILED',$fName); return false; } bzclose($handle); } $pageOwner['files'][$fName.$compressType] = 1; } ////////////////////////////////////////////////////////////////// // // Send Message to User // if( $exists ){ $href = wbLinks::special('Image_Manager?cmd=rename&from='.htmlspecialchars($fName.$compressType).'&to='.htmlspecialchars($exists.$compressType),false); message('UPLOADED_RENAMED',$exists,$fName,$href,$exists); }else{ message('UPLOADED',$fName); } //show Images if( $isImage ){ $this->showImage($fName,$data); $pageOwner['disk_usage'] = $diskUsage + $fileSize; return true; }else{ //use the size of the compressed file $stats = stat($destinationFile); $fileSize = $stats['size']; $pageOwner['disk_usage'] = $diskUsage + $stats['size']; return true; } } function viewFile(){ if( isset($_GET['fName']) ){ if( (wbStrpos($_GET['fName'],'/') !== false) || (wbStrpos($_GET['fName'],'\\') !== false) ){ trigger_error('Invalid file name: '.$_GET['fName']); return; } } $this->showImage($_GET['fName']); } function showImage($fName,$data=false){ global $page,$pageOwner,$rootDir,$dbObject,$lang,$jsNum; $page->scripts[] = '/include/'.$jsNum.'/fileManager.js'; /// $data if( !$data ){ $fPath = $this->path.'/'.$fName; $data = @getimagesize($fPath); if( !$data ){ message('NOT_AN_IMAGE','3'); return false; } } /// Variables $wikiSyntax = '[[image:'.$fName.']]'; $fileLocation = '/userfiles/'.toStorage($pageOwner['username'],true).'/uploaded/'.$fName; $html = '<img src="'.wbLinks::getDir($fileLocation).'" height="'.$data[1].'" width="'.$data[0].'" alt="'.$fName.'" />'; $style = 'style="border:1px solid #d4d0c8;padding:2px;"'; /// Output ob_start(); echo '<div style="text-align:center">'; echo $html; echo '</div>'; echo '<table class="tableRows" cellpadding="4" cellspacing="4" width="100%">'; echo '<tr><th width="50%">'.$lang['file_info'].'</th><th width="50%">'.$lang['options'].'</th></tr>'; echo '<tr><td>'; if( !isset($pageOwner['imgs'][$fName]) ){ $pageOwner['imgs'][$fName] = $data[0].'x'.$data[1]; } echo '<ul><li>'.$lang['width'].': '.$data[0].'</li>'; echo '<li>'.$lang['height'].': '.$data[1].'</li>'; echo '<li>'.$lang['file_location'].': '.wbLinks::getDir($fileLocation).'</li>'; echo '<li>'.$lang['wiki_syntax'].': <input type="text" size="40" value="'.htmlspecialchars($wikiSyntax).'" '.$style.' /></li>'; echo '<li>'.$lang['html_syntax'].': <input type="text" size="40" value="'.htmlspecialchars($html).'" '.$style.' /></li>'; echo '</ul></td>'; echo '<td>'; echo '<ul>'; //echo '<li><input type="submit" name="cmd['.htmlspecialchars($fName).']" value="'.$lang['delete'].'"> </li>'; echo '<li>'.wbLinks::special('Image_Manager?cmd=delete&fName='.htmlspecialchars($fName),'delete').'</li>'; echo '</ul></td></tr></table>'; $dbObject->links[$fName] = '/Special/'.$pageOwner['username'].'/Image_Manager?cmd=view&fName='.$fName; $page->formAction = $dbObject->links[$fName]; $page->contentA[$fName] = wb::get_clean(); } // Populate the $pageOwner['imgs'] array if needed // // function checkPageOwner($force=false){ global $pageOwner; if( $this->checked ){ return; } if( !$force ){ if( isset($pageOwner['imgs']) ){ return; } } if( !is_dir($this->path) ){ return; } $dh = opendir($this->path); if( !$dh ){ return; } $pageOwner['files'] = array(); $pageOwner['imgs'] = array(); $pageOwner['disk_usage'] = 0; while (($file = readdir($dh)) !== false) { $fullPath = $this->path.'/'.$file; if( is_dir($fullPath) ){ continue; } if( $file{0} === '.' ){ continue; } $data = false; $temp=explode(".",$file); $file_type = array_pop($temp); $file_type = strtolower($file_type); if( isset($this->imgs[$file_type]) ){ $data = @getimagesize($fullPath); } if( !$data && isset($this->safe[$file_type]) ){ $pageOwner['files'][$file] = 1; }elseif($data){ $pageOwner['imgs'][$file] = $data[0].'x'.$data[1]; }else{ continue; } $stats = stat($fullPath); $fileSize = $stats['size']; $pageOwner['disk_usage'] += $stats['size']; } closedir($dh); $this->checked=true; }}new fileManager();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -