PHP scandir资源管理器视图通过WAMP显示网络共享文件(文件://)。在本地主机上运行,但不能通过IP地址运行 [英] PHP scandir explorer view to display network share files (file://) via WAMP. Works on localhost but not by IP address
问题描述
我可以在访问 http:// localhost ,但是如果从同一个本地主机访问http:// [our_external_ip_address],那么文件不会打开。状态栏中的路径在两者上显示相同(例如file://computername/share/filename.zip)。我最终希望将这些文件放在与我们的虚拟主机相同的网络上。
请帮忙。我相当能胜任PHP& JS,但是当涉及到网络主机等,我塞满了。 TIA。
James
非常感谢DaveRandom - 这个解决方案努力允许从外部Web客户端启动UNC路径中的PDF / Word / Zip文件。
$ b 文件1: - index.php
<?php
$ filename = ***插入UNC文件路径*** // eg \\share\computername\New Document.doc
$ extension = pathinfo($ filename,PATHINFO_EXTENSION); //获取文件扩展名
$ displayFilename = ***插入缩短文件名*** // New Document.doc
?>
< a href =filehandler.php?name =<?php echo $ filename;?>& ext =<?php echo $ extension;?> & shortname =<?php echo $ displayFilename;?>><?php echo $ displayFilename; ?>< / A>
文件2: - filehandler.php b
<?php
$ filename = $ _GET ['name'];
$ extension = $ _GET ['ext'];
$ shortfilename = $ _GET ['shortname'];
if($ extension ==pdf)
{
header(Content-type:application / pdf); ($ extension =doc)
{
header(Content-type:application / msword); //作为一个pdf文件浏览器
}
。 ($ extension =zip)
{
header(Content-type:application / zip); //作为doc文件浏览
}
。 //作为一个zip文件浏览器
header(Content-Disposition:inline; filename ='$ shortfilename');
$ file = readfile($ filename);
echo $ file;
?>
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
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;
?>
这篇关于PHP scandir资源管理器视图通过WAMP显示网络共享文件(文件://)。在本地主机上运行,但不能通过IP地址运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!