DotDragnet
May 24, 2012, 09:39:22 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: PHP accessing files across a network  (Read 371 times)
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« on: January 17, 2012, 06:27:07 PM »

I have two servers, one runs an intranet on IIS7 (win 2008 server). I need this to be able to access PDF files stored on a second (windows) server. As the content of the PDF files are sensitive (they're payslips) I can't just create direct links to the files as users won't have actual access to the directory holding the PDFs. So instead I'm using PHP to get the file and present it for download.

If I put the PDF file on the local C drive of the intranet server, the code works. It gets the PDF file specified and allows me to download it. However, across server it just comes back with the php file that I'm running for download.

My code for reference is

Code:
$filename = realpath($pdfpath);

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".@filesize($filename));
set_time_limit(0);
@readfile("$filename") or die("File not found.");

I've had a look online and have found several people trying to perform similar operations. The main suggestion we've seen and also read on the Microsoft site was to make the intranet server run as a specific local user (as opposed to the IIS User - IUSR) and then give them access to the folder on the network drive with the PDFs in. Tried this and it also doesn't work. My other thought was to somehow map a drive specific to the server, as obviously the intranet is accessed via a browser and users don't actually log into the intranet server.

I realise that this isn't standard due to the security risks but as this is all internal and limited to just a directory on a different server I would hope that there's still a way around it.

The paths I've tried have been

\\servername\directory\pathtopdf.pdf
\\\\servername\\directory\\pathtopdf.pdf

We also tried setting up the directory as a virtual directory within IIS7 and used ..\virtualdirectory\pathtopdf.pdf but again no joy, and to be honest I doubt it would as PHP isn't working via the browser but via the file system essentially.

Anyway, any suggestions or thoughts appreciated.

Just to add, we're running PHP 5.3.4 and I have full access to edit the php.ini file.

tia smile
Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #1 on: January 17, 2012, 09:53:58 PM »

What is with all those headers? This is HTTP not MIME.

I haven't done anything on Windows for millennia, but I don't think realpath works across networked filesystems (not sure it does on Linux come to think of it).

The \\\\servername\\directory\\pathtopdf.pdf form should be correct, might also be worth trying file://servername/directory/pathtopdf.pdf
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #2 on: January 18, 2012, 08:29:47 AM »

The code is what I picked up at some point some time ago, it worked, I assumed it was fine smile I'll have another look around for alternate code. I'll try the file:// method as I don't think I've tried that.

Cheers smile
Logged

sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #3 on: January 19, 2012, 01:18:47 PM »

Turns out it was a permissions issue despite me being told all permissions were set. A bit of digging and I seem to have fixed it. I've also cleaned up the PHP code so thanks for the tip on that smile
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!