Ljrbrasil 0 Denunciar post Postado Março 3, 2010 pessoal tenho este codigo para leitura de arquivos do servidor, estou precisando criar mais uma coluna e criar um botao que possa deletar o arquivo do servidor alguem pode ajudar nesta. <?PHP //Check if directory is valid $folder_exists = 1; if(!is_dir($dir_to_browse)) { $folder = ""; $folder_exists = 0; } if($folder_exists == 0) { echo display_error_message("<b>Error:</b>esta pasta não existe. This could be because you manually entered the folder name in the URL or you don't have permission to access this folder"); exit; } //Chcek if directory is valid -done //This is a VERY important security feature. It wont allow people to browse directories above $dir_to_browse. Edit this part at your own risk $folders_in_URL_security = explode("../",$folder); if(count($folders_in_URL_security) > 1) { echo display_error_message("<b>Access Denied.</b>"); exit; } //Seurity feature -done //Create navigation links $this_file_name_array = explode("/",$_SERVER['PHP_SELF']); $this_file_name = array_pop($this_file_name_array); $folders_in_URL = explode("/",rawurldecode($folder)); $depth = count($folders_in_URL); foreach($folders_in_URL as $key => $val) { $_temp = $_temp."/".$val; $folders_in_URL_array[$key] = $_temp; if($key == 0) { $_temp = $folders_in_URL[0]; $folders_in_URL_array[0] = $folders_in_URL[0]; } } $nav_links = "<a href=\"$this_file_name\">home</a>/"; for($i=0;$i<$depth;$i++) { if(!empty($folder)) $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>/"; else $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>"; } //Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays $dir_content = get_dir_content($dir_to_browse); if($case_sensative_ext == 0) { foreach($exclude_ext as $key => $val) { $temp_ext = $val; $exclude_ext[$key] = strtolower($temp_ext); } } //If file extensions are NOT case sensative -done //Filter content $filtered_content = array(); $filter_count = 0; foreach($dir_content as $key => $val) { $file_ext = explode(".",$val); $file_ext = ".".array_pop($file_ext); if(!in_array($val, $exclude) && !in_array($file_ext,$exclude_ext)) { $filtered_content[$filter_count] = $val; $filter_count++; } } if($exclude_this_file == 1) { $array_with_this_file_name = array(); $temp_filtered_content = $filtered_content; $filtered_content = array(); foreach($temp_filtered_content as $key => $val) { if($val == $this_file_name) { array_push($array_with_this_file_name, $key); } else $filtered_content[$key] = $val; } foreach($array_with_this_file_name as $key => $val) { $temp_path = $folder."/".$this_file_name; if(substr($temp_path,0,1) == "/") $temp_path = substr($temp_path,1); if(is_file($temp_path)) { $md5_temp_path = md5_file($temp_path); $md5_this_file = md5_file($_SERVER['SCRIPT_FILENAME']); if($md5_temp_path != $md5_this_file) { array_push($filtered_content, $this_file_name); } } else array_push($filtered_content, $this_file_name); } } //Filter content -done //Get directory content and seperate files and folders into 2 arrays -done if(!empty($filtered_content)) { $folders_count = 0; $files_count = 0; $folders_array = array(); $files_array = array(); foreach($filtered_content as $key => $val) { $path = $dir_to_browse.$val; if(is_dir($path)) { array_push($folders_array, $val); } else { array_push($files_array, $val); } } //Sort the files and folders arrays if(!empty($folders_array)) natcasesort($folders_array); if(!empty($files_array)) natcasesort($files_array); $folders_array_temp = array(); $files_array_temp = array(); foreach($folders_array as $key => $val) { array_push($folders_array_temp, $val); } foreach($files_array as $key => $val) { array_push($files_array_temp, $val); } $folders_array = $folders_array_temp; $files_array = $files_array_temp; //Sort the files and folders arrays -done //Determin OS PHP is running on if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $OS = "windows"; //Get files and folders sizes and creation dates $folders_cdate_array = array(); $files_cdate_array = array(); $folders_size_array = array(); $files_size_array = array(); $files_total_size = 0; $folders_total_size = 0; foreach($files_array as $key => $val) { $path = $dir_to_browse.$val; $files_cdate_array[$key] = date("d F Y", filectime($path)); $file_bytes = filesize($path); $files_size_array[$key] = letter_size($file_bytes); $files_total_size = $files_total_size + $file_bytes; } foreach($folders_array as $key => $val) { $path = $dir_to_browse.$val; $path_slash = $dir_to_browse.$val."/"; $folders_cdate_array[$key] = date("d F Y", filectime($path)); if($show_folder_size) { if($OS == "windows") $folder_bytes = folder_size_windows($path_slash); else $folder_bytes = folder_size($path); $folders_size_array[$key] = letter_size($folder_bytes); $folders_total_size = $folders_total_size + $folder_bytes; } else $folders_size_array[$key] = "-"; } //Get files and folders sizes and creation dates -done //Generate content links to an array $folders_links_array = array(); $files_links_array = array(); foreach($folders_array as $key => $val) { $folders_links_array[$key] = '<a href="'.$this_file_name.'?folder='.rawurlencode($folder_slash).rawurlencode($val).'">'.$val."</a><br>"; } foreach($files_array as $key => $val) { if(empty($folder)) $files_links_array[$key] = '<a href="'.$dir_to_browse_original.rawurlencode($val).'">'.$val."<br>"; else $files_links_array[$key] = '<a href="'.$dir_to_browse_original.$folder."/".rawurlencode($val).'">'.$val."</a><br>"; } //Generate content links to an array -done //Calculate table dimensions $table_width = (6*$cell_padding) + (4*$cell_spacing) + $width_of_files_column + $width_of_sizes_column + $width_of_dates_column; //calculate table dimensions -done //Palce the content into a table if($legend) echo " <table width=\"320\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"table_border\"> <tr> <td width=\"100\" bgcolor=\"#666666\"><font color=\"#FFFFFF\"><strong>KEY</strong></font></td> <td width=\"33\">Pasta</td> <td width=\"24\"><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$folder_color\"> </td> </tr> </table></td> <td width=\"17\">Arquivo</td> <td width=\"24\"><table width=\"24\" height=\"4\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$color_1\"> </td> </tr> </table> </td> <td width=\"5\">|</td> <td><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$color_2\"> </td> </tr> </table></td> </tr> </table><br>"; if($statistics) { echo' <a href="javascript:;" onMouseDown="if(document.getElementById(\'mydiv\').style.display == \'none\'){ document.getElementById(\'mydiv\').style.display = \'block\'; }else{ document.getElementById(\'mydiv\').style.display = \'none\'; }">Show/hide statistics<br></a> <div id="mydiv" style="display:none"> <table width="320" border="0" cellpadding="5" class="table_border">'; if($show_folder_size) echo'<tr> <td width="95" bgcolor="#666666"><font color="#FFFFFF"><strong>pastas </strong></font></td> <td>'.count($folders_array).', tamanho: '.letter_size($folders_total_size).'</td> </tr>'; echo' <tr> <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">arquivos </font></strong></td> <td>'.count($files_array).', tamanho: '.letter_size($files_total_size).'</td> </tr>'; if($show_folder_size) echo'<tr> <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">Total </font></strong></td> <td>'.(count($folders_array)+count($files_array)).', tamanho: '.letter_size(($files_total_size+$folders_total_size)).'</td> </tr></table>';} echo" </table></div><br><table width=\"$table_width\" border=\"0\" cellspacing=\"$cell_spacing\" cellpadding=\"$cell_padding\"> <tr> <td width=\"$width_of_files_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">arquivo</span></td> <td width=\"$width_of_sizes_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">tamanho</span></td> <td width=\"$width_of_dates_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Data</span></td> </tr>"; foreach($folders_links_array as $key => $val) { echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$folder_color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$folder_color\">$folders_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$folders_cdate_array[$key]</td></tr>"; } foreach($files_links_array as $key => $val) { if($key%2 == 0) $color = $color_1; else $color = $color_2; echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$color\">$files_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$color\">$files_cdate_array[$key]</td></tr>"; } echo "</table>"; //Palce the content into a table -done //Closing curley brace for the if(!empty($filtered_content)) } //Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays -done //Output if there is no content if(empty($filtered_content)) echo display_error_message("Sem arquivos no diretorio: <span class=\"path_font\"><b>$folder</b></span>"); //Output if there is no content -done //Functions function get_dir_content($path) { $php_version = substr(phpversion(),0,1); if($php_version > 4) { $content = scandir($path); return $content; } elseif($php_version == 4) { $content = array(); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { array_push($content,$file); } closedir($handle); } return $content; } } function folder_size($path) { $folder_size = `du -s $path`; $size_array = explode("\t", $folder_size); return $size_array[0]*1024; } function folder_size_windows($path) { $exclude = array('.','..'); $content = scandir($path); //Filter content $filtered_content = array(); $filtered_content = array(); foreach($content as $key => $val) { if(!in_array($val, $exclude)) { array_push($filtered_content, $val); } } //Filter content -done foreach($filtered_content as $key => $val) { $content_path = $path.$val; if(is_dir($content_path)) { $content_path = $path.$val."/"; $directory_size = folder_size_windows($content_path); $total_directory_size = $total_directory_size + $directory_size ; } else { $file_size = filesize($content_path); $total_file_size = $total_file_size + $file_size; } } return ($total_file_size + $total_directory_size); } function letter_size($byte_size) { $file_size = $byte_size/1024; if ($file_size >= 1048576) { $file_size = $file_size/1048576; $file_size = sprintf("%01.2f", $file_size); $file_size = $file_size." GB"; } elseif ($file_size >= 1024) { $file_size = $file_size/1024; $file_size = sprintf("%01.2f", $file_size); $file_size = $file_size." MB"; } else { $file_size = sprintf("%01.1f", $file_size); $file_size = $file_size." KB"; } return $file_size; } function display_error_message($message) { return "<table width=\"80%\" cellpadding=\"5\" cellspacing=\"1\" class=\"table_border\"> <tr> <td bgcolor=\"#FFBBBD\">$message</td> </tr> </table>"; } //Functions -done //Display load time if($load_time) { $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "<br>pagina criada em ".sprintf("%.3f", $totaltime)." segundos"; } //Display load time -done ?> Compartilhar este post Link para o post Compartilhar em outros sites
ozorio silva 0 Denunciar post Postado Março 3, 2010 ola cara da unlink no php para deletar o arquivo http://www.php.net/manual/pt_BR/function.unlink.php <input type=button value='Deletar' onClick="window.location='deletar.php';"> <?php $deletar= unlink(caminho do arquivo/nome do arquivo); if($deletar==true){ print("ARQUIVO DELETADO COM SUCESSO"); } else{ print("ERRO"); } ?> Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 3, 2010 Ozorio desculpe pois sou novato. mas poderia me dizer onde exatamente eu consigo inserir o codigo? fico grato. Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 4, 2010 Ozorio desculpe pois sou novato. mas poderia me dizer onde exatamente eu consigo inserir o codigo? fico grato. entao a tela hoje esta assim, precisava colocar a linha de comando que voce passou Compartilhar este post Link para o post Compartilhar em outros sites
Matias Rezende 50 Denunciar post Postado Março 4, 2010 Na outra coluna da tabela do HTML, você coloca algo assim <a href="pagina.php?arquivo=nomeDoArquivo">Excluir</a> Aí, na pagina.php você utiliza o código que o ozorio silva postou, pegando o nome do arquivo por GET. Mais ou menos assim: if(isset($_GET['arquivo']) && is_writable($_GET['arquivo'])) { unlink($_GET['arquivo']); } else { echo 'Houve um erro ao tentar excluir o arquivo'; } http://br.php.net/manual/en/function.is-writable.phphttp://br.php.net/isset Carlos Eduardo Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 5, 2010 Matias você sempre me ajudando como pode. então consegui ler o codigo mas realmente nao consegui inserir a informação no sistema, o codgio que o ozorio colocou eu acho que a palavra arquivo sera subistituida por folder. desta maneira. if(isset($_GET['folder']) && is_writable($_GET['folder'])) { unlink($_GET['folder']); } else { echo 'Houve um erro ao tentar excluir o arquivo'; } agora se puder me ajudar informando onde posso inserir a o codigo fico grato. se puder me add no msn ljrbrasil@hotmail.com Compartilhar este post Link para o post Compartilhar em outros sites
pedrokl 0 Denunciar post Postado Março 5, 2010 Opa, entao eu dei uma lida por cima ai no codigo e ACHO que pra fazer a coluna do excluir tu tem que colocar aqui echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$folder_color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$folder_color\">$folders_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$folders_cdate_array[$key]</td> <td width=\"tamanho_da_coluna_excluir\" bgcolor=\"$folder_color\"><a href="pagina.php?arquivo=nomeDoArquivo">Excluir</a></td> </tr>"; na verdade tem que colocar $_GET['arquivo'] mesmo, porque ele vai pegar o que estiver depois do "pagina.php?arquivo=" ai tu coloca o codigo do Matias que resolve! Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 5, 2010 Pedrokl Obrigado pela ajuda mas ao inserir a linha de comando informada o sistema deu erro Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\EasyPHP 2.0b1\www\teste\administracao\adm\downloadss.php on line 477 Compartilhar este post Link para o post Compartilhar em outros sites
Matias Rezende 50 Denunciar post Postado Março 6, 2010 Qual a linha 477? Poste também algumas linhas antes e algumas linhas depois. Carlos Eduardo Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 6, 2010 foreach($folders_links_array as $key => $val) { echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$folder_color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$folder_color\">$folders_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$folders_cdate_array[$key]</td> LINHA 447 <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\"><a href="pagina.php?arquivo=nomeDoArquivo">Excluir</a></td></tr>"; } Compartilhar este post Link para o post Compartilhar em outros sites
Matias Rezende 50 Denunciar post Postado Março 6, 2010 Escape as aspas. Assim: <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\"><a href=\"pagina.php?arquivo=nomeDoArquivo\">Excluir</a></td></tr>"; Carlos Eduardo Compartilhar este post Link para o post Compartilhar em outros sites
Ljrbrasil 0 Denunciar post Postado Março 16, 2010 Matia desculpe demora a responder e que relamente precisei viajar. bom estive vendo o que voce colocou e veja eu codigo esta assim os em vermelhos foi o que voces colocaram pra mim. o que acontece e que quero deletar alguns arquivos que encontra-se na pasta /www/administracao/painel/arquivos e o arquvio de visualização fica na pasta. /www/administracao/adm. fico grato. pela ajuda. <?PHP $dir_to_browse = "../painel/arquivos/"; //default = "./" //Exclude this file from being listed? 1:Yes 2:No $exclude_this_file = 1; //Files or folders to exclude from listing - note:index.php is this file by default. $exclude = array('.','..','.ftpquota','.htaccess'); //Files to exclude based on extension (eg: '.jpg' or '.PHP') and weather to be case sensative. 1:Enable 0:Disable $exclude_ext = array(''); $case_sensative_ext = 1; //default = 1 //Enable/Disable statistics/legend/load time. 1:Enable 0:Disable $statistics = 1; //default = 1 $legend = 1; //default = 1 $load_time = 1; //default = 1 //Show folder size? Disabling this will greatly improve performance if there are several hundred folders/files. However, size of folders wont show. 1:Enable 0:Disable $show_folder_size = 1; //default = 1 $color_1 = "#FF9933"; $color_2 = "#FF9933"; $folder_color = "#CCCCCC"; //Table formatting $top_row_bg_color = "#006699"; $top_row_font_color = "#FFFFFF"; $width_of_files_column = "450"; $width_of_sizes_column = "100"; $width_of_dates_column = "125"; $cell_spacing = "5"; $cell_padding = "5"; if($load_time) { $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; } //Start load time -done if(get_magic_quotes_gpc()) $folder = stripslashes($_GET['folder']); else $folder = $_GET['folder']; $dir_to_browse_original = $dir_to_browse; if(!empty($folder)) { $dir_to_browse = $dir_to_browse.$folder."/"; $folder_slash = $folder."/"; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>°°Sistema de °°</title> <link href="../style.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- #apDiv1 { position:absolute; left:133px; top:203px; width:149px; height:177px; z-index:1; } .style1 {color: #FDFF60} --> </style> <script src="../../Scripts/AC_ActiveX.js" type="text/javascript"></script> <script src="../../Scripts/AC_RunActiveContent.js" type="text/javascript"></script> <script src="../../upload/js/jquery.js" type="text/javascript"></script> <script src="../../upload/js/efeitos.js" type="text/javascript"></script> </head> <body oncontextmenu="return false" > <table width="755" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><div align="center" class="te_branco"><a href="http://www.br/administracao/painel/listar_logins.php"> </a><a href="http://www.br/administracao/painel/listar_logins.php">...</a> SISTEMA <a href="http://www.br/administracao/painel/mens.php"> ...</a></div></td> </tr> <tr> <td> </td> </tr> <tr> <td width="1002"><table border="0" cellpadding="0" cellspacing="0" width="754"> <!-- fwtable fwsrc="Untitled" fwpage="Page 1" fwbase="inteno.jpg" fwstyle="Dreamweaver" fwdocid = "2089891039" fwnested="0" --> <tr> <td><img src="../painel/spacer.gif" width="8" height="1" border="0" alt="" /></td> <td><img src="../painel/spacer.gif" width="737" height="1" border="0" alt="" /></td> <td><img src="../painel/spacer.gif" width="9" height="1" border="0" alt="" /></td> <td><img src="../painel/spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td colspan="2"><img name="inteno_r1_c1" src="../../imagens/inteno_r1_c1.jpg" width="745" height="11" border="0" id="inteno_r1_c2" alt="" /></td> <td rowspan="2" valign="top" background="../painel/imagens/inteno_r1_c3b.jpg"><img name="inteno_r1_c3" src="../../imagens/inteno_r1_c3.jpg" width="9" height="90" border="0" id="inteno_r1_c4" alt="" /></td> <td><img src="../painel/spacer.gif" width="1" height="11" border="0" alt="" /></td> </tr> <tr> <td background="../../imagens/inteno_r2_c1.jpg"> </td> <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="13%"><div align="center"><a href="../painel/adm.php"><img src="../../imagens//voltar.png" width="64" height="64" border="0" /></a></div></td> <td width="14%"><div align="center"><a href="listar_logins.php"><img src="../../imagens/relatorio.png" width="64" height="64" border="0" /></a></div></td> <td width="16%"><div align="center"><a href="cad.php"><img src="../../imagens/USUARIO.png" width="64" height="64" border="0" /></a></div></td> <td width="14%"><div align="center"></div> <div align="center"></div> <div align="center"><img src="../../imagens//envio.png" width="64" height="64" border="0" /></div></td> <td width="13%"><div align="center"><a href="../noticias/noticias.php"><img src="../../imagens/NOTICIAS.png" width="64" height="64" border="0" /></a></div></td> <td width="16%"><div align="center"><a href="downloads.php"><img src="../../imagens/downloads.png" width="64" height="64" border="0" /></a></div></td> <td width="14%"><div align="center"></div> <div align="center"><a href="../painel/logoff.php"><img src="../../imagens//sair.png" width="64" height="64" /></a></div></td> </tr> <tr> <td><div align="center"><span class="te_azul"><a href="../painel/adm.php" class="te_azul">VOLTAR</a></span></div></td> <td><div align="center"><span class="te_azul"><a href="listar_logins.php" target="_blank" class="te_azul">RELAT. VISITAS</a></span></div></td> <td><div align="center"><span class="te_azul"><a href="cad.php" class="te_azul">NOVO USUARIO</a></span></div></td> <td><div align="center"></div> <div align="center"><span class="te_azul">ENVIO DE DOC</span></div></td> <td><div align="center"></div> <div align="center"></div> <div align="center"><span class="te_azul"><a href="../noticias/noticias.php" class="te_azul">NOTÍCIAS</a></span></div></td> <td class="te_azul"><div align="center"><a href="downloads.php" class="te_azul">DOWNLOADS</a></div></td> <td><div align="center"></div> <div align="center"><a href="../painel/logoff.php" class="te_azul">SAIR</a></div></td> </tr> </table></td> <td><img src="../painel/spacer.gif" width="1" height="79" border="0" alt="" /></td> </tr> <tr> <td colspan="3"><img name="inteno_r3_c1" src="../../imagens/inteno_r3_c1.jpg" width="754" height="10" border="0" id="inteno_r3_c2" alt="" /></td> <td><img src="../painel/spacer.gif" width="1" height="10" border="0" alt="" /></td> </tr> </table></td> </tr> <tr> <td height="19"> </td> </tr> <tr> <td height="10"><table border="0" cellpadding="0" cellspacing="0" width="754"> <!-- fwtable fwsrc="Untitled" fwpage="Page 1" fwbase="inteno.jpg" fwstyle="Dreamweaver" fwdocid = "2089891039" fwnested="0" --> <tr> <td><img src="../../spacer.gif" width="8" height="1" border="0" alt="" /></td> <td><img src="../../spacer.gif" width="737" height="1" border="0" alt="" /></td> <td><img src="../../spacer.gif" width="9" height="1" border="0" alt="" /></td> <td><img src="../../spacer.gif" width="1" height="1" border="0" alt="" /></td> </tr> <tr> <td colspan="2"><img name="inteno_r1_c1" src="../../imagens/inteno_r1_c1.jpg" width="745" height="11" border="0" id="inteno_r1_c1" alt="" /></td> <td rowspan="2" valign="top" background="../../imagens/inteno_r1_c3b.jpg"><img name="inteno_r1_c3" src="../../imagens/inteno_r1_c3.jpg" width="9" height="90" border="0" id="inteno_r1_c3" alt="" /></td> <td><img src="../../spacer.gif" width="1" height="11" border="0" alt="" /></td> </tr> <tr> <td width="8" background="../../imagens/inteno_r2_c1.jpg"> </td> <td valign="top" bgcolor="#FFFFFF"><table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td valign="top"><table width="95%" border="0" align="center"> <tr> <td width="698" height="15"><div align="center" class="te_preto"> <div align="left">VERIFIQUE SEU ARQUIVO.</div> </div></td> </tr> <tr> <td> <p align="left"> <?PHP //Check if directory is valid $folder_exists = 1; if(!is_dir($dir_to_browse)) { $folder = ""; $folder_exists = 0; } if($folder_exists == 0) { echo display_error_message("<b>Error:</b>esta pasta não existe. This could be because you manually entered the folder name in the URL or you don't have permission to access this folder"); exit; } //Chcek if directory is valid -done //This is a VERY important security feature. It wont allow people to browse directories above $dir_to_browse. Edit this part at your own risk $folders_in_URL_security = explode("../",$folder); if(count($folders_in_URL_security) > 1) { echo display_error_message("<b>Access Denied.</b>"); exit; } //Seurity feature -done //Create navigation links $this_file_name_array = explode("/",$_SERVER['PHP_SELF']); $this_file_name = array_pop($this_file_name_array); $folders_in_URL = explode("/",rawurldecode($folder)); $depth = count($folders_in_URL); foreach($folders_in_URL as $key => $val) { $_temp = $_temp."/".$val; $folders_in_URL_array[$key] = $_temp; if($key == 0) { $_temp = $folders_in_URL[0]; $folders_in_URL_array[0] = $folders_in_URL[0]; } } $nav_links = "<a href=\"$this_file_name\">home</a>/"; for($i=0;$i<$depth;$i++) { if(!empty($folder)) $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>/"; else $nav_links = $nav_links."<a href=\"$this_file_name?folder=".rawurlencode($folders_in_URL_array[$i])."\">$folders_in_URL[$i]</a>"; } //Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays $dir_content = get_dir_content($dir_to_browse); if($case_sensative_ext == 0) { foreach($exclude_ext as $key => $val) { $temp_ext = $val; $exclude_ext[$key] = strtolower($temp_ext); } } //If file extensions are NOT case sensative -done //Filter content $filtered_content = array(); $filter_count = 0; foreach($dir_content as $key => $val) { $file_ext = explode(".",$val); $file_ext = ".".array_pop($file_ext); if(!in_array($val, $exclude) && !in_array($file_ext,$exclude_ext)) { $filtered_content[$filter_count] = $val; $filter_count++; } } if($exclude_this_file == 1) { $array_with_this_file_name = array(); $temp_filtered_content = $filtered_content; $filtered_content = array(); foreach($temp_filtered_content as $key => $val) { if($val == $this_file_name) { array_push($array_with_this_file_name, $key); } else $filtered_content[$key] = $val; } foreach($array_with_this_file_name as $key => $val) { $temp_path = $folder."/".$this_file_name; if(substr($temp_path,0,1) == "/") $temp_path = substr($temp_path,1); if(is_file($temp_path)) { $md5_temp_path = md5_file($temp_path); $md5_this_file = md5_file($_SERVER['SCRIPT_FILENAME']); if($md5_temp_path != $md5_this_file) { array_push($filtered_content, $this_file_name); } } else array_push($filtered_content, $this_file_name); } } //Filter content -done //Get directory content and seperate files and folders into 2 arrays -done if(!empty($filtered_content)) { $folders_count = 0; $files_count = 0; $folders_array = array(); $files_array = array(); foreach($filtered_content as $key => $val) { $path = $dir_to_browse.$val; if(is_dir($path)) { array_push($folders_array, $val); } else { array_push($files_array, $val); } } //Sort the files and folders arrays if(!empty($folders_array)) natcasesort($folders_array); if(!empty($files_array)) natcasesort($files_array); $folders_array_temp = array(); $files_array_temp = array(); foreach($folders_array as $key => $val) { array_push($folders_array_temp, $val); } foreach($files_array as $key => $val) { array_push($files_array_temp, $val); } $folders_array = $folders_array_temp; $files_array = $files_array_temp; //Sort the files and folders arrays -done //Determin OS PHP is running on if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') $OS = "windows"; //Get files and folders sizes and creation dates $folders_cdate_array = array(); $files_cdate_array = array(); $folders_size_array = array(); $files_size_array = array(); $files_total_size = 0; $folders_total_size = 0; foreach($files_array as $key => $val) { $path = $dir_to_browse.$val; $files_cdate_array[$key] = date("d F Y", filectime($path)); $file_bytes = filesize($path); $files_size_array[$key] = letter_size($file_bytes); $files_total_size = $files_total_size + $file_bytes; } foreach($folders_array as $key => $val) { $path = $dir_to_browse.$val; $path_slash = $dir_to_browse.$val."/"; $folders_cdate_array[$key] = date("d F Y", filectime($path)); if($show_folder_size) { if($OS == "windows") $folder_bytes = folder_size_windows($path_slash); else $folder_bytes = folder_size($path); $folders_size_array[$key] = letter_size($folder_bytes); $folders_total_size = $folders_total_size + $folder_bytes; } else $folders_size_array[$key] = "-"; } //Get files and folders sizes and creation dates -done [color="#FF0000"][b]if(isset($_GET['$val']) && is_writable($_GET['$val'])) { unlink($_GET['$val']); } else { echo 'Houve um erro ao tentar excluir o arquivo'; } [/b][/color] //Generate content links to an array $folders_links_array = array(); $files_links_array = array(); foreach($folders_array as $key => $val) { $folders_links_array[$key] = '<a href="'.$this_file_name.'?folder='.rawurlencode($folder_slash).rawurlencode($val).'">'.$val."</a><br>"; } foreach($files_array as $key => $val) { if(empty($folder)) $files_links_array[$key] = '<a href="'.$dir_to_browse_original.rawurlencode($val).'">'.$val."<br>"; else $files_links_array[$key] = '<a href="'.$dir_to_browse_original.$folder."/".rawurlencode($val).'">'.$val."</a><br>"; } //Generate content links to an array -done //Calculate table dimensions $table_width = (6*$cell_padding) + (4*$cell_spacing) + $width_of_files_column + $width_of_sizes_column + $width_of_dates_column; //calculate table dimensions -done //Palce the content into a table if($legend) echo " <table width=\"320\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" class=\"table_border\"> <tr> <td width=\"100\" bgcolor=\"#666666\"><font color=\"#FFFFFF\"><strong>KEY</strong></font></td> <td width=\"33\">Pasta</td> <td width=\"24\"><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$folder_color\"> </td> </tr> </table></td> <td width=\"17\">Arquivo</td> <td width=\"24\"><table width=\"24\" height=\"4\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$color_1\"> </td> </tr> </table> </td> <td width=\"5\">|</td> <td><table width=\"24\" height=\"24\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"> <tr> <td colspan=\"4\" bgcolor=\"$color_2\"> </td> </tr> </table></td> </tr> </table><br>"; if($statistics) { echo' <a href="javascript:;" onMouseDown="if(document.getElementById(\'mydiv\').style.display == \'none\'){ document.getElementById(\'mydiv\').style.display = \'block\'; }else{ document.getElementById(\'mydiv\').style.display = \'none\'; }">Show/hide statistics<br></a> <div id="mydiv" style="display:none"> <table width="320" border="0" cellpadding="5" class="table_border">'; if($show_folder_size) echo'<tr> <td width="95" bgcolor="#666666"><font color="#FFFFFF"><strong>pastas </strong></font></td> <td>'.count($folders_array).', tamanho: '.letter_size($folders_total_size).'</td> </tr>'; echo' <tr> <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">arquivos </font></strong></td> <td>'.count($files_array).', tamanho: '.letter_size($files_total_size).'</td> </tr>'; if($show_folder_size) echo'<tr> <td width="95" bgcolor="#666666"><strong><font color="#FFFFFF">Total </font></strong></td> <td>'.(count($folders_array)+count($files_array)).', tamanho: '.letter_size(($files_total_size+$folders_total_size)).'</td> </tr></table>';} echo" </table></div><br><table width=\"$table_width\" border=\"0\" cellspacing=\"$cell_spacing\" cellpadding=\"$cell_padding\"> <tr> <td width=\"$width_of_files_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">arquivo</span></td> <td width=\"$width_of_sizes_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">tamanho</span></td> <td width=\"$width_of_dates_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Data</span></td> <td width=\"$width_of_dates_column\" bgcolor=\"$top_row_bg_color\"><span class=\"top_row\">Excluir</span></td> </tr>"; foreach($folders_links_array as $key => $val) { echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$folder_color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$folder_color\">$folders_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$folders_cdate_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\">$val[$key]</td></tr>"; } foreach($files_links_array as $key => $val) { if($key%2 == 0) $color = $color_1; else $color = $color_2; echo"<tr> <td width=\"$width_of_files_column\" bgcolor=\"$color\">$val</td> <td width=\"$width_of_sizes_column\" bgcolor=\"$color\">$files_size_array[$key]</td> <td width=\"$width_of_dates_column\" bgcolor=\"$color\">$files_cdate_array[$key]</td> [color="#FF0000"][b] <td width=\"$width_of_dates_column\" bgcolor=\"$folder_color\"><a href=\"pagina.php?arquivo=nomeDoArquivo\">Excluir</a></td></tr>";[/b][/color] } echo "</table>"; //Palce the content into a table -done //Closing curley brace for the if(!empty($filtered_content)) } //Get directory content (filtered(without the excluded specified above)) and seperate files and folders to 2 arrays -done //Output if there is no content if(empty($filtered_content)) echo display_error_message("Sem arquivos no diretorio: <span class=\"path_font\"><b>$folder</b></span>"); //Output if there is no content -done //Functions function get_dir_content($path) { $php_version = substr(phpversion(),0,1); if($php_version > 4) { $content = scandir($path); return $content; } elseif($php_version == 4) { $content = array(); if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { array_push($content,$file); } closedir($handle); } return $content; } } function folder_size($path) { $folder_size = `du -s $path`; $size_array = explode("\t", $folder_size); return $size_array[0]*1024; } function folder_size_windows($path) { $exclude = array('.','..'); $content = scandir($path); //Filter content $filtered_content = array(); $filtered_content = array(); foreach($content as $key => $val) { if(!in_array($val, $exclude)) { array_push($filtered_content, $val); } } //Filter content -done foreach($filtered_content as $key => $val) { $content_path = $path.$val; if(is_dir($content_path)) { $content_path = $path.$val."/"; $directory_size = folder_size_windows($content_path); $total_directory_size = $total_directory_size + $directory_size ; } else { $file_size = filesize($content_path); $total_file_size = $total_file_size + $file_size; } } return ($total_file_size + $total_directory_size); } function letter_size($byte_size) { $file_size = $byte_size/1024; if ($file_size >= 1048576) { $file_size = $file_size/1048576; $file_size = sprintf("%01.2f", $file_size); $file_size = $file_size." GB"; } elseif ($file_size >= 1024) { $file_size = $file_size/1024; $file_size = sprintf("%01.2f", $file_size); $file_size = $file_size." MB"; } else { $file_size = sprintf("%01.1f", $file_size); $file_size = $file_size." KB"; } return $file_size; } function display_error_message($message) { return "<table width=\"80%\" cellpadding=\"5\" cellspacing=\"1\" class=\"table_border\"> <tr> <td bgcolor=\"#FFBBBD\">$message</td> </tr> </table>"; } //Functions -done //Display load time if($load_time) { $mtime = microtime(); $mtime = explode(" ",$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); echo "<br>pagina criada em ".sprintf("%.3f", $totaltime)." segundos"; } //Display load time -done ?> </p> <p align="left"> </p> <p align="left"></p> <p align="center"></p> <p align="right"> </p> <p align="right"> </p> <p align="right"> </p> <p align="right"> </p></td> </tr> </table></td> </tr> </table> </td> <td><img src="../../spacer.gif" width="1" height="79" border="0" alt="" /></td> </tr> <tr> <td colspan="3"><img name="inteno_r3_c1" src="../../imagens/inteno_r3_c1.jpg" width="754" height="10" border="0" id="inteno_r3_c1" alt="" /></td> <td><img src="../../spacer.gif" width="1" height="10" border="0" alt="" /></td> </tr> </table></td> </tr> <tr> <td background="../../imagens/pek.png"><img src="../../imagens/pek.png" width="6" height="7" /></td> </tr> <tr> <td><span class="style4">7</span></td> </tr> <tr> <td height="30" background="../../imagens/menu.jpg"><div align="center"><strong>by: Lecio Junior</strong></div></td> </tr> </table> </body> </html> Compartilhar este post Link para o post Compartilhar em outros sites