rcs2008
asked on
Opening File over UNC path
I am trying to use php to open a PDF file. I have been able to access the share and I know permissions are working just wondering what might be going wrong. Below is the code and also a screen shot of what i see
$file = '//revere-acct/start$/NOT_PROCESSED/400000104_PR_D32555_20100121_000.PDF';
$Out.= "<br /><iframe src='".$file."' style=\"width:750px; height:1000px;\" frameborder=\"0\"></iframe>";
RCS-MyPanel---Employee-126463501.png
ASKER
Yes the share is on "Computer A" webserver is on "Computer B" and I am accessing from "Computer C"
You are trying to use the FILE protocol and not the HTTP protocol.
So, try file:/// (yes 3 slashes) and then the UNC path.
BUT!!!!!
I think FireFox blocks links to local files (local as in file:/// protocol).
So, try file:/// (yes 3 slashes) and then the UNC path.
BUT!!!!!
I think FireFox blocks links to local files (local as in file:/// protocol).
ASKER
Any idea how I could make the webserver push it to me?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The readfile() function is the important bit. The headers there were to force a save dialogue.
ASKER
I am trying to display the file via UNC and within the users browser, below is an example
RCS-MyPanel---Employee-126469351.png
RCS-MyPanel---Employee-126469351.png
It all comes down to the headers. In the end, I ended up forcing downloads as trying to consistently open certain files is a pain.
ASKER
the only type of file I want to display in the browser is a PDF
Aha.
Can you try ...
<?php
header('HTTP/1.1 200 OK', True, 200);
header('Content-Type: application/pdf');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($PhysicalFileName ));
readfile($PhysicalFileName );
exit();
?>
Can you try ...
<?php
header('HTTP/1.1 200 OK', True, 200);
header('Content-Type: application/pdf');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($PhysicalFileName
readfile($PhysicalFileName
exit();
?>
If the file is on a share, you might want to stream the data to the browser as opposed to referring the browser to a share which the user might not have access to.
i.e. print "content type: application/pdf"
Print the pdf file to the browser or setup a script on your web server
http:/myserver/document.php?documentid=32343
The script based on the documentid will open the applicable file and will stream it.
i.e. print "content type: application/pdf"
Print the pdf file to the browser or setup a script on your web server
http:/myserver/document.php?documentid=32343
The script based on the documentid will open the applicable file and will stream it.
I'm using the code below without any issues to stream files from a windows share to browsers. You only have to be sure that the user the webserver is running under has access to the drive and file.
$file='\\\\revere-acct\\start$\\NOT_PROCESSED\\400000104_PR_D32555_20100121_000.PDF';
if(file_exists($file)) {
$fh=fopen($file, "rb");
header("Content-Type: application/pdf");
header("Content-Length: " . filesize($file));
header("Content-Disposition: attachment; filename=\"400000104_PR_D32555_20100121_000.PDF\"");
fpassthru($fh);
} else {
echo "Could not find this file";
}
When you accessed the share were you doing it from the computer where firefox is or on the computer where the PHP code is running.
I am assuming that the PHP code is running on a Web server that is on a different computer from the browser.