通过运行 wshell 命令在 PHP 中创建文件夹


creating folder in php by running wshell command

我想通过命令提示符运行一个php文件,我已经在php代码中使用了mkdir来制作目录。
但是当我从 cmd/wshell 命令执行代码时,永远不会创建该文件夹。

//i use this when i run the test.php file from cmd.
C:'wamp'bin'php'php5.5.12'php-win.exe -f c:'wamp'www'test'test.php

测试.php包含:

<?php
    mkdir("C://wamp/www/test/testrr",0777,true);
    file_put_contents("C://wamp/www/test/del.txt","lol");
?>

将创建 del.txt 文件,但永远不会创建"testrr"文件夹。
我以管理员身份运行了该命令。

授予 %system32%''cmd.exe 对 IUSR 帐户的读取/执行权限。或者你可以使用SysInternals Pseexec:

<?php
exec("md 'data'");
?>

或使用 Windows 脚本外壳 COM 对象:

<?php
function _exec($cmd)
{
   $WshShell = new COM("WScript.Shell");
   $oExec = $WshShell->Run($cmd, 0,false);
   echo $cmd;
   return $oExec == 0 ? true : false;
}_exec("whatever");
?>