Im trying to read a file in a shared network folder which i can reach but php doesnt have access to.
The shared folder "xtern" is located on computer "saturn" and the file is called "seq_ws.csv".
here is my code:
<?php
$fileURL = "\\saturn\xtern\seq_ws.csv";
$fileAvailable = file_exists($fileURL);
if($fileAvailable){
echo "Succes";
}else{
echo "fail";
echo file_get_contents($fileURL);
}
?>
which results in the following;
fail
Warning: file_get_contents(\saturn\xtern\seq_ws.csv): failed to open stream: No such file or directory in C:\Apache24\htdocs\file.php on line 9
The strange thing is that i can open the path in both a browser and windows explorer just fine and read the file. The shared folder has all permissions for the user I run Apache on aswell as all permissions for "Everyone".
I have tried researching this problem but havent been able to find any solution. I have checked php.ini
and allow_url_fopen
is set to On
. Im pretty sure it is a setting within Apache, PHP or the shared folder somewhere since i can read the file as stated before but just not with my PHP script.
If anybody has any information or suggestion it would be gladly appreciated,
Thanks in advance.
After much more searching of this problem I finally found the answer, the problem with a UNC path is that the Apache service cant get into shared folders on default(maybe its a bug) cause of the way the service is set up. To fix this problem you gotta link Apache to a user profile, I dont know if this is only a problem in Windows.
To fix fix Apache not being able to access shared folders:
services.msc
Local System account
to This account
and fill in a account name and passwordIf you dont want to keep the same account as your Localhost
to connect to the shared folder just duplicate the name and password into the textboxes.
I hope this will help others that encounter the same problem as I did. While researching this i found many people that did and many diffrent comments/answers but nothing worked.