cacohr
Abrir diretório da rede e listar arquivos
30 de June de 2009 às 12:09AM
PessoALL

Criei um sistema que verifica se um arquivo existe em um diretório. Caso ele exista, inclui ele como anexo em um e-mail. Quando coloco para listar um diretório local (no servidor) ele funciona bem. Mas preciso que ele liste um diretório que está em outro servidor (ex: \\servidor2\arquivos), mas quando coloco o caminho dessa forma ele dá erro. Mapeei esse caminho no servidor (z:), mas mesmo assim continua dando erro. Se puderem me ajudar agradeço, falta só esse detalhe e já pesquisei bastante, mas até agora nada resolveu.

Abaixo tem a parte do código que faz essa listagem.


$diretorio = "c:/apache/htdocs/dirteste";
$ponteiro = opendir($diretorio);
while ($nome_itens = readdir($ponteiro)) {
$itens[] = $nome_itens;
}
sort($itens);
foreach ($itens as $listar) {
if ($listar!="." && $listar!=".."){
$arquivos[]=$listar;
}
}


O erro q dá é na abetura do diretório (opendir).
Agradeço a ajuda pessoal, falta só isso pra terminar o sistema e entregar pro cliente....
cacohr
Re: Abrir diretório da rede e listar arquivos
30 de June de 2009 às 11:50AM
Mensagem de Erro:

Warning: OpenDir: Invalid argument (errno 22) in c:\apache\htdocs\sis_convenio\enviar_convenio.php on line 73
cacohr
Re: Abrir diretório da rede e listar arquivos
30 de June de 2009 às 01:52PM
Galera, consegui resolver o problema com essa dica ques estava no manual do php (http://br.php.net/function.opendir). Valeu mesmo assim, mas caso alguém precise dessa informação, abaixo está o texto que me ajudou.


when you run Apache as a service on your Windows computer, it chooses to run as the LocalSystem account by default (usually SYSTEM). The LocalSystem account has no network privileges whatsoever which, while no doubt a good thing, makes it impossible to access networked resources (such as a shared drive) in your Apache service.

First, you have to change the user the Apache service runs as.
Go to your Services panel (Start -> Run -> "services.msc").
Find the Service labeled Apache, right-click, and hit Properties.
Choose the "Log On" tab.
Presumably you'll see that Apache is set up to run as the Local System Account. You'll want to change this to the second option, "This account", and then fill in the details of the User account you would like Apache to run under.
Some sites tell you to create a special Apache-based user account just for this occasion. It's not a bad idea, but then you have to make sure it has all of the proper permissions that an Apache user would need, such as read/write to to htdocs and the .conf and .log files, and permissions to log on as a service, etc etc - as well as the permissions to access the network resource you're trying to get to in the first place.
In light of that process, I chose to just run it under my own account instead. Once you get it working, you can go back and create that special account.
Hit "Apply" - it'll pop up a box saying you need to restart Apache to take effect, but hold off on that for a moment.
This is the tricky part: you have to give the user (the one you're running Apache as) permissions to act as part of the OS.
Go to the Local Security Policy panel (Start -> Run -> "secpol.msc").
Under the navigation section in the left sidebar, choose Local Policies -> User Rights Assignments.
In the right-hand frame, double-click the item "Act as part of the operating system" to open up its properties.
Select "Add User or Group, Enter the appropriate user in the box provided, and hit "OK."
At this point, you are technically complete - Apache can now do the same things to the network resource that your user can - read, write, execute, whatever. However, in my case, I was trying to create an actual readable resource, so I edited my Apache config file to create an alias to my share.
Open up your Apache configuration file. For most people it's httpd.conf in the conf subdirectory of your Apache install directory.
Add the following text to your config file (obviously substituting your UNC for "//servername/sharename" and renaming ALIAS_DIRECTORY to whatever you'd like):

Alias /ALIAS_DIRECTORY "//servername/sharename"

<Directory "//servername/sharename">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory
The other thing that is tricky and caught me up is that unlike Windows UNCs, the Apache config file requires forward slashes, not backslashes. So if you're copying the UNC directly from Windows, you'll have to turn all those slashes around.

Now you can restart your Apache service. Take a swing over to http://your.site.name/ALIAS_DIRECTORY and you should be able to view the network resource just fine.


Valeu e t+
Você precisa estar logado no PHPBrasil.com para poder enviar mensagens para os nossos fóruns.

Faça o login aqui.