PHP scandir explorer view to display network share files (file://) via WAMP. Works on localhost but not by IP address

无人久伴 提交于 2019-12-11 18:23:13

问题


Maybe I am being daft, or misunderstanding either WAMP restrictions or browser restrictions, but I have created a PHP file explorer view using the scandir function recursively using Ajax, and it works great to display the files from our network share (\computername\share).

I can launch the files when accessing http://localhost, however if from the same localhost machine I access http://[our_external_ip_address] then the files do not open. The path in the status bar displays the same on both (e.g. file://computername/share/filename.zip). I eventually want to put the files on a network share which is on the same domain as our web host machine.

Please help. I am fairly competent with PHP & JS but when it comes to web hosts and the like, I am stuffed. TIA.

James


回答1:


Massive thanks to DaveRandom - this solution worked to allow PDF / Word / Zip files from a UNC path to be launched from an external web client.

FILE 1: - index.php

<?php
    $filename= *** insert UNC path to file *** // e.g. \\share\computername\New Document.doc
    $extension= pathinfo($filename, PATHINFO_EXTENSION); // Gets extension for file
    $displayFilename= *** insert shorten filename *** // e.g. New Document.doc
?>


<a href="filehandler.php?name=<?php echo $filename; ?>&ext=<?php echo $extension; ?>&shortname=<?php echo $displayFilename; ?>"><?php echo $displayFilename; ?></a>

FILE 2: - filehandler.php

<?php
$filename = $_GET['name'];
$extension = $_GET['ext'];
$shortfilename = $_GET['shortname'];
if ($extension == "pdf")
{
    header("Content-type: application/pdf"); // act as a pdf file to browser
}
if ($extension == "doc")
{
    header("Content-type: application/msword"); // act as a doc file to browser
}
if ($extension == "zip")
{
    header("Content-type: application/zip"); // act as a zip file to browser
}
header("Content-Disposition: inline; filename='$shortfilename'"); 

$file = readfile($filename);
echo $file;
?>


来源:https://stackoverflow.com/questions/10121903/php-scandir-explorer-view-to-display-network-share-files-file-via-wamp-wor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!