Fopen Permission denied

Asked

Viewed 775 times

1

I’m trying to read a file TXT on the network, but the PHP always returns permission error. The folder is shared and I can see it over the network windows.

Server use Windows with IIS7.

In the xampp local I can access these files via php normal.

ini_set('display_errors',1);
error_reporting(E_ALL);

$ponteiro = fopen ("//192.168.1.2\DADOSTXT\arquivo.TXT","r") or die("ERRO");

while(!feof($ponteiro)){
  $linha = fgets($ponteiro,4096);
  echo $linha."<br>";
}

fclose ($ponteiro);

Some help ?

  • 1

    you’ll have to give Apache permission to read this file on the network, see if it helps: http://phpbrasil.com/phorum/read.php?11,163196. If you can, share. :)

1 answer

1


There are some details to be corrected:

  1. Instead of //192.168.1.2\ you must use \\192.168.1.2\
  2. You must "escape" the character \ leaving him like this \\\\192.168.1.2\\DADOSTXT\\arquivo.TXT

network/Domain Account

If this does not solve the problem you will need to use a network/Domain account for Apache to gain access:

  1. Open the Start menu -> Run (or Windowkey+R) and type services.msc then press "Enter".
  2. Search for Apache (or wampapache)
  3. Right-click on this service and select "Properties".
  4. Go to the tab "Logon".
  5. Select the "radio button" where it says "You are account:", the fields will be enabled then enter the credentials so that you need apache to have access. If it is a domain/network account use syntax DOMAIN\nome-do-usuario (or use the search to find the account using the "Search...")
  6. Click OK and restart the Apache service (if wamp restarts on wamp itself).
  7. To check if the changes worked go to Taskmanager (task manager or Ctrl+Alt+Del) and see if which username appears next to the Apache process (httpd.exe)

Browser other questions tagged

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