Access denied. (code: 5) PHP

Asked

Viewed 1,362 times

1

I am using the code below to try to read the files in a directory.

$dir = "\\\\192.168.44.19\Controles\Inventario de Equipamentos\A\ " ;
$pasta= opendir($dir);


echo("<li data-role='list-divider'><a href='#'>B</a></li>"); 

while ($arquivo = readdir($pasta)){
  if ($arquivo != '.' && $arquivo != '..'){
     echo "<li><a href='".$dir.$arquivo."' rel='external' >".$arquivo."</a></li>";
  }
}

But I get the message from error:

Access denied. (code: 5) in C: wamp www terms index.php on line 30

  • Manually, by My Computer or by accessing the Linux Terminal address 192.168.44.19\Controles\Inventario de Equipamentos\A\ you can easily access?

  • you need to change the folder permission for reading, if you are using linux do sudo chmod -R 777 "nome da pasta"

  • @Rafaelacioly chmod 777 is a bit dangerous. it just needs reading access.

  • @Giancarlogiulian, yes. Access normally.

  • @Rafaelacioly, my user has Total Control in the folder

  • @Moshmage, it’s just for internal use. I don’t know if I’d have much trouble

  • Make a is_dir($dir), checks if the return is true.

  • @Deesouza false

  • It means it doesn’t exist. Make sure that this is the way ?

  • @Deesouza, check the path. Really was incorrect. I corrected, but still the error remains.

  • These four bars at the beginning are normal ? I’ve never seen this. It would be nice if you renamed the folders and left them without spaces.

  • @Deesouza with or without the 4 bars, same error. The folders unfortunately have no way to rename ...

  • Try to access the machine name instead of your IP.

Show 8 more comments

2 answers

1


Solution found

It is necessary to configure the service with some network user who has access to the directory. I went to Start>Run>services.Msc and found the wampapache service. Then right-click>properties>logon and put the account data with access.

Solved

0

Lucas, this problem may be linked to several factors, internal or even external to the language, such as: Firewall, Network, Folder and User Permissions.

Firewall

The computer that is being accessed is with firewall or ant-virus that is not letting the host in.

Network

Network is properly allowed in folder sharing, network group and etc?

Folder permissions

Folder permissions are correct and share correctly on the network? permissions for specific users or group?

In windows is little weak permissions management, outside Windows Server that is the largest control. Take a look at this.

If the machine you are accessing is UNIX terminal you need to set read permissions for the folder:

chmod 0755 /path/folder/ -R

Well, it’s not a code error apparently, but rather host permissions. Take a look at these tips and tell me what you found.

  • Thanks for the answer. Firewall and Antivirus are disabled. Regarding the network, my user is with full access. Regarding the server, I am using a virtual box inside a Windows Server.

  • Through the browser you normally have access to the share?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.