在php中创建批处理文件以解压缩多个文件

时间:2023-01-19 18:42:03

Here is my code which works:

这是我的代码有效:

<?php

$string = "e:
cd randomddirectory
unzip -o 84557".date("ymd")."*.zip -d Extracted";

file_put_contents("extract.bat", $string);

?>

But when I try to account for multiple files to be unzipped like below, it fails:

但是,当我尝试将多个文件解释为如下所述解压缩时,它会失败:

<?php

$string = "e:
cd randomddirectory
unzip -o 84557".date("ymd")."*.zip -d Extracted
unzip -o 84539".date("ymd")."*.zip -d Extracted
unzip -o 84527".date("ymd")."*.zip -d Extracted
unzip -o 84509".date("ymd")."*.zip -d Extracted";

file_put_contents("extract.bat", $string);

?>

How do I modify the syntax to get the multiple unzips working? It's important the command is all within one string like above.

如何修改语法以使多个解压缩工作?重要的是命令都在上面的一个字符串中。

1 个解决方案

#1


0  

My guess is that unzip is a batch file on its own here. So put call before the unzip to make it work:

我的猜测是unzip本身就是一个批处理文件。因此,在解压缩之前调用它以使其工作:

$string = "cd /d e:\\randomddirectory 
call unzip -o 84557".date("ymd")."*.zip -d Extracted 
call unzip -o 84539".date("ymd")."*.zip -d Extracted 
call unzip -o 84527".date("ymd")."*.zip -d Extracted 
call unzip -o 84509".date("ymd")."*.zip -d Extracted";

I still think there are more sensible ways of doing this than creating a batch file and calling it from PHP. You'd run into probably every possible security barrier with this anyway.

我仍然认为有更明智的方法来创建一个批处理文件并从PHP调用它。无论如何,你可能会碰到所有可能的安全障碍。

#1


0  

My guess is that unzip is a batch file on its own here. So put call before the unzip to make it work:

我的猜测是unzip本身就是一个批处理文件。因此,在解压缩之前调用它以使其工作:

$string = "cd /d e:\\randomddirectory 
call unzip -o 84557".date("ymd")."*.zip -d Extracted 
call unzip -o 84539".date("ymd")."*.zip -d Extracted 
call unzip -o 84527".date("ymd")."*.zip -d Extracted 
call unzip -o 84509".date("ymd")."*.zip -d Extracted";

I still think there are more sensible ways of doing this than creating a batch file and calling it from PHP. You'd run into probably every possible security barrier with this anyway.

我仍然认为有更明智的方法来创建一个批处理文件并从PHP调用它。无论如何,你可能会碰到所有可能的安全障碍。