Accessing files from different domains using php

I have PDF documents stored in a shared folder on a server where I need to access them from a web application through a file viewer. I know the names of the files stored there. So my link will be like ( file: \\ server \ folder \ abc.pdf ).

My php app is on a web server running xampp. But the shared folder is on a different domain. (Not in the web server folder - regular file folder). When I try to access the file, it says " Can't find file: \\ server \ folder \ abc.pdf. Make sure the path or internet address is correct .

<a href="file:\\server\folder\abc.pdf" >Load File</a> 

<?php 
echo $dir = '\\\\server\\folder\\'; 

$dh = opendir($dir); 

while (($file = readdir($dh)) !== false) { 
echo "<a href=".$dir.$file.">".$file."<br></a>"; 
} 

closedir($dh); 

?>

      

When I type "\\ server \ folder" in the address bar, it asks for the username and password of this folder, since it is in a different domain (my current domain has already been authenticated in my sign). When I provide Windows Authentication for this folder, my web app url works and opens the file successfully.

I want to complete this task without asking for a username and password to secure the directory. My web application will be used by many users, so local mapping of a network drive is not possible either.

Can anyone help me on this please?

+3


source to share


1 answer


Got an answer

We can map a network drive to the server and save the username and password that are requested in the "network drive" wizard, and then we can use the connected networks wizard.



Below is the code that worked for me.

$dir = "A:/folder/";
$dh = opendir($dir);
while (($file = readdir($dh)) !== false)
{
 echo 'The file is : ' . $file . "\n";
}
closedir($dh);

      

+1


source







All Articles