Re: Displaying files

From: Date: Fri, 15 Aug 2008 13:50:59 +0000
Subject: Re: Displaying files
References: 1 2 3 4 5 6 7 8 9 10 11  Groups: php.general 
Request: Send a blank email to php-general+get-278133@lists.php.net to get a copy of this message
On 15 Aug 2008, at 14:26, Dan Shirah wrote:
Because as I mentioned before PHP runs as a different user to your browser. -Stut Stut, Are you referring to this? "If you're using IIS then it's the IUSR_machine user which doesn't have access to the network by default" The IUSR_SERVERNAME account is what it should be connecting as whether I'm using PHP/Javascript/HTML, unless specifically set in a connection string such as the database connections. But, the initial calls always come from IUSR_SERVERNAME.
You need to understand that there are 2 sides to a web-based application, the client and the server. When you link the browser to a file (as in your HTML and JS code below) it's the *client* that's accessing the file. Neither IIS nor PHP get involved in that. This works because the browser is running as you and has sufficient permissions to access that network location. When you try to do the same with PHP it is running as the IUSR_SERVERNAME user which, by default and for good reason, cannot access network shares in that way. The link I gave you should give you enough information to enable the required access for that user, but you might want to think carefully before doing so since it's disabled by default for security reasons. -Stut
Thiago, HTML WORKS <a href=\\server\folder\file.xls target="_blank">Open</a> Javascript WORKS function openWin(folder,file) { var LeftPosition = (this.screen.width) / 2; var TopPosition = (this.screen.height) - this.screen.height; var Height = (this.screen.height) - 90; var Width = (this.screen.width) /2 - 10; MyWin = window.open(\\\\server\\"+folder+"\\"+file
+"\.xls","ViewImage","scrollbars=yes, status=yes,          resizable=no,top="+TopPosition+",left="+LeftPosition+",width="+Width+",height="+Height+"");
MyWin.focus(); } PHP DOESN'T WORK $filename = "\\\\server\\".$folder."\\".$file.".xls"; header("Content-Type: application/x-msdownload"); readfile($filename); I put all three of these examples into the exact same page. The HTML and Javascript open the file without any problems, but PHP cannot open it.
-- http://stut.net/

« previous php.general (#278133) next »