简体   繁体   English

从 PHP 打开 Windows 文件夹

[英]Open Windows folder from PHP

I need just to open a windows explorer from PHP.我只需要从 PHP 打开一个 Windows 资源管理器。 I tried this: https://github.com/cztomczak/phpdesktop but doesn't work.我试过这个: https : //github.com/cztomczak/phpdesktop但不起作用。 I just want to press a button or anything and open a window from windows NOT BROWSE FILE TO UPLOAD, just open a window THANK YOU.我只想按一个按钮或任何东西,然后从 Windows 中打开一个窗口,而不是浏览要上传的文件,只需打开一个窗口,谢谢。

Usually, PHP runs on a server and dynamically prepares an HTML document which is then displayed by your browser.通常,PHP 在服务器上运行并动态准备一个 HTML 文档,然后由您的浏览器显示。
In this case, what you want to do is not possible .在这种情况下,您想要做的事情是不可能的

If you run PHP on your windows machinge as a scripting language instead, this is possible.如果您在 Windows 机器上运行 PHP 作为脚本语言,这是可能的。 This is the code you would need:这是您需要的代码:

chdir($path);
exec("start .");

Note that PHP's chdir function might have trouble navigating to long directory paths.请注意,PHP 的 chdir 函数可能无法导航到长目录路径。 EG "C:\\Program Files (x86)\\Development Server\\binaries\\php\\php713vc14x86x200518222354".例如“C:\\Program Files (x86)\\Development Server\\binaries\\php\\php713vc14x86x200518222354”。 If your paths go many folders deep then consider using something like this.如果您的路径深入许多文件夹,请考虑使用这样的东西。

NavigateToDirectory($Path);
function NavigateToDirectory($Directory){
    $Directory = explode('\\', $Directory);
    for($i=0; $i<count($Directory); $i++)
        if(is_dir($Directory[$i]))
            chdir($Directory[$i]);
}
$path = "G:\\android_batch_8";
exec("EXPLORER /E,$path");

i have used above code and it is working perfectly but one problem is how open this folder in maximized window?我已经使用了上面的代码,它运行良好,但一个问题是如何在最大化窗口中打开这个文件夹?

Php is server side Scripting language. Php 是服务器端脚本语言。 it cannot perform any action on client side computer like opening explorer window.It can only store some cookies on client side that's it.它不能在客户端计算机上执行任何操作,例如打开资源管理器窗口。它只能在客户端存储一些 cookie。 you can use this你可以用这个

<input type="file"></input>

this is html which is used to open explore window to upload files.这是用于打开浏览窗口以上传文件的 html。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM