Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP&;在XAMPP中虚拟浏览Windows文件系统;htaccess_Php_.htaccess - Fatal编程技术网

使用PHP&;在XAMPP中虚拟浏览Windows文件系统;htaccess

使用PHP&;在XAMPP中虚拟浏览Windows文件系统;htaccess,php,.htaccess,Php,.htaccess,我正在开发一个应用程序,可以在web浏览器中浏览Windows文件系统。这最初是为了让我妻子能够查看存储在连接到运行XAMPP的网络计算机的外部硬盘上的照片,从而减少安装任何软件的需要。我已经允许观看电影,浏览音乐,等等,使用各种技术来服务内容。呜呼 使用httpd.conf(Apache Config)中的以下命令访问文件系统没有问题: 然后创建$path变量: if (isset($_GET['q1'])) { $q1=($_GET['q1']); $path=$q1."/"; } 然后将

我正在开发一个应用程序,可以在web浏览器中浏览Windows文件系统。这最初是为了让我妻子能够查看存储在连接到运行XAMPP的网络计算机的外部硬盘上的照片,从而减少安装任何软件的需要。我已经允许观看电影,浏览音乐,等等,使用各种技术来服务内容。呜呼

使用httpd.conf(Apache Config)中的以下命令访问文件系统没有问题:

然后创建$path变量:

if (isset($_GET['q1'])) {
$q1=($_GET['q1']);
$path=$q1."/";
}
然后将$path变量送入scan_dir:

$scan_dir="H:/$path";
$files_or_folders = scandir($scan_dir); 
然后遍历结果,将带有一些附加逻辑(不包括)的$file\u或\u folder变量更改为文件链接或文件夹链接:

foreach($files_or_folders as $key => $file_or_folder){
// if files
// display pictures or other content
<a href="<?= $file; ?>"><?= $file ?></a>
// if folders
// display a link to the folder
<a href="index.php<?= $query."=".$folder; ?>"><?= $folder ?></a>
}
解析文件路径所需的代码更糟糕:

if (isset($_GET['q1']) && isset($_GET['q2']) && !isset($_GET['q3'])){
$q1=($_GET['q1']);
$q2=($_GET['q2']);
    $q3=($_GET['q3']);
$path=$q1."/".$q2."/".$q3;
$query="?q1=$q1&q2=$q2&q3";
}
我认为使用.htaccess重定向请求比用这种方式获取文件路径更优雅。因此,我修改了代码,将“/level_A/level_B/level_C”重定向到index.php,并通过以下方式创建要输入scan_dir()的路径信息:

#get uri (everything after www root)
$request = $_SERVER['REQUEST_URI'];

#explode the path by '/'   
$folders  = explode("/", $request); 

ob_start();
#loop through the results
foreach ($folders as $folder) {
echo $folder;
echo "/";
}
#save ob results in variable
$path = ob_get_clean();
因此,文件夹链接现在如下所示:

<a href="<?= $path.$folder ?>">$folder/a>

为什么不打开它呢?这对浏览文件系统非常有用。但是,我希望创建一个应用程序,不同的用户可以在其中创建帐户,并从中创建书签、收藏、相册等。我也有它的设置,使一个文件夹的图像可以被视为一个幻灯片或作为一个画廊的图像。
if (isset($_GET['q1']) && isset($_GET['q2']) && !isset($_GET['q3'])){
$q1=($_GET['q1']);
$q2=($_GET['q2']);
    $q3=($_GET['q3']);
$path=$q1."/".$q2."/".$q3;
$query="?q1=$q1&q2=$q2&q3";
}
#get uri (everything after www root)
$request = $_SERVER['REQUEST_URI'];

#explode the path by '/'   
$folders  = explode("/", $request); 

ob_start();
#loop through the results
foreach ($folders as $folder) {
echo $folder;
echo "/";
}
#save ob results in variable
$path = ob_get_clean();
<a href="<?= $path.$folder ?>">$folder/a>