Good morning. I have been there for at least two days trying to find a solution to the problem I am facing. I'm still new to php and so much trouble ...
Well, the problem is this: I want to create a web application to use here in enterprise IT. This application consists of navigating through a folder structure that I will make available on the network. The final goal is for me to pick up the folder indicated by the user. "But why this?" Someone might ask. Then the answer: The user needs to fill out an electronic form and one of the fields in this form consists of the user specifying the full path of the folder where he wants access. So that the user does not have to be copying the path through Explorer (windows), he would do it directly by the application,
Well, I was able to implement the navigation and I ended up in a problem: folders with names like "my folder is pure action". That is, folder with accentuation.
When I pass this type of path I get the error: "The system can not find the specified file (code: 2) in C: \ xampp \ htdocs \ test \ requisicao.php on line 44"
I would like somebody to help me solve this problem.
Here is the code for anyone who can help: index.php :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ajax com jQuery</title>
<style type="text/css"> #box {border:1px solid #ccc; padding:5px} </style>
</head>
<body>
<legend>Setor desejado</legend>
<select id="select_setor" onchange="">
<option id="null" value="null">Selecione o Setor</option>
<option id="adm" value="adm">Administrativo</option>
<option id="com" value="com">Comercial</option>
<option id="dir" value="dir">Diretoria</option>
<option id="ope" value="ope">Operacional</option>
<option id="pro" value="pro">Produtivo</option>
<option id="qua" value="qua">Qualidade</option>
</select>
<div>
<legend id="raiz">Diretorio: </legend>
<div id="dir_setor"></div>
</div>
<div>
<legend>Escolhidos (form com ajax)</legend>
<div id="box"></div>
</div>
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#select_setor").change(function(event) {
$("#null").attr('disabled','disabled');
var setor = $("#select_setor").val();
setLegenda();
$("#dir_setor").load('requisicao.php',{setor:setor},ready());
});
});
function getDir(e) {
var name = e.name;
var subs = '//10.40.0.200/Diretorios/Setores/';
var legenda = "Diretorio: " + name.replace(subs, '');
document.getElementById('raiz').innerHTML = legenda;
$("#dir_setor").load('requisicao.php',{diretorio:name},ready());
}
function setLegenda(){
var subs = '//10.40.0.200/Diretorios/Setores/';
var selected = $('#select_setor :selected').text();
var legenda = "Diretorio: " + selected.replace(subs, '');
document.getElementById('raiz').innerHTML = legenda;
}
function ready(){}
</script></html>
And this is the request.php :
<?php
ini_set( 'default_charset', 'utf-8');
$setor = (array_key_exists('setor', $_POST) ? $_POST['setor'] : null);
$diretorio = (array_key_exists('diretorio', $_POST) ? $_POST['diretorio'] : null);
$dirNome = $diretorio;
if($setor == null){
$setor = '//10.40.0.200/Diretorios/Setores/';
$abreDir = $diretorio;
}else{
$diretorio = '//10.40.0.200/Diretorios/Setores/';
switch($setor){
case 'adm':
$setor = '//10.40.0.200/Diretorios/Setores/Administrativo/';
break;
case 'com':
$setor = '//10.40.0.200/Diretorios/Setores/Comercial/';
break;
case 'dir':
$setor = '//10.40.0.200/Diretorios/Setores/Diretoria/';
break;
case 'ope':
$setor = '//10.40.0.200/Diretorios/Setores/Operacional/';
break;
case 'pro':
$setor = '//10.40.0.200/Diretorios/Setores/Produtivo/';
break;
case 'qua':
$setor = '//10.40.0.200/Diretorios/Setores/Qualidade/';
break;
}
$abreDir = $setor;
}
$openDir = dir($abreDir);
$tempDir = explode('/', $dirNome);
$backDir = $abreDir;
$indice = count($tempDir) - 2;
if($indice > 2){ $backDir = str_replace($tempDir[$indice].'/', "", $dirNome); }
$table = '';
$table .= '<table id="table_dir" style="border=1px ">';
while ($arq = $openDir -> read()) {
if($arq != '.' && $arq != '..'){
if(is_dir($abreDir.$arq)){
$arq = utf8_encode($arq);
$abreDir = utf8_encode($abreDir);
$table .= '<tr>';
$table .= '<td>';
$table .= $arq;
$table .= '</td>';
$table .= '<td><a name="';
$table .= $abreDir.$arq;
$table .= '/" href="#" class"href_dir" onclick="getDir(this)"> Abrir </a></td>';
$table .= '</tr>';
}else{
if(strpos('~$', $arq)){
echo '<tr>';
echo '<td>'.$arq.'</td>';
echo '<td> -- </td>';
echo '</tr>';
}
}
}
}
$table .= '</table>';
echo $table;
if ($abreDir != $setor) { echo '<td><a name="'.$backDir.'" href="#" class"href_dir" onclick="getDir(this)"> Voltar </a></td>'; }
$openDir->close(); ?>