Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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
我们可以从URL到批处理文件动态地获取php值吗?_Php_Server_Copy_Vpn - Fatal编程技术网

我们可以从URL到批处理文件动态地获取php值吗?

我们可以从URL到批处理文件动态地获取php值吗?,php,server,copy,vpn,Php,Server,Copy,Vpn,这是我的批处理文件脚本。我正在通过任务调度器运行此脚本 通过使用下面的脚本,我能够将所有文件从invoice_feed文件夹复制到网络共享测试文件夹shared_文件夹,这两个服务器都通过VPN连接 Echo off net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username xcopy C:\Apache\htdocs\Invoices\invoice_feed \\w

这是我的批处理文件脚本。我正在通过任务调度器运行此脚本 通过使用下面的脚本,我能够将所有文件从invoice_feed文件夹复制到网络共享测试文件夹shared_文件夹,这两个服务器都通过VPN连接

Echo off
net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username
xcopy C:\Apache\htdocs\Invoices\invoice_feed \\windows_servername\\test_folder
如果我想将一个特定的文件复制到网络共享文件夹,那么我将手动将该文件添加到上面的批处理脚本中,它运行良好。下面是代码

Echo off
net use \\windows_servername\test_folder shared_folder_password /user:shared_folder_username
xcopy C:\Apache\htdocs\Invoices\invoice_feed\file_to_copy.csv \\windows_servername\\test_folder
我可以使用PHP运行这个脚本吗?如果是,那么我可以从URL中传递动态值,并传递该值来代替下面的特定文件名吗

xcopy C:\Apache\htdocs\Invoices\invoice_feed\<?php echo $_GET['csv_file_name']?> \\windows_servername\\test_folder

但是没有运气。它显示已复制的0个文件。我哪里做错了?

在批处理文件中,您可以传递参数并捕获该参数

batchname.bat arg1 arg2 在批处理文件中,您可以捕获如下参数

set arg1=%1
set arg2=%2
xcopy C:\Apache\htdocs\Invoices\invoice_feed\%arg1% \\windows_servername\\test_folder
因此,如果从php触发此批处理,则可以轻松地将get参数作为参数传递给批处理文件

您可以使用系统函数运行批处理文件

$last_line = system("cmd /c C:/path/to/bat/batchname.bat ".$_GET['csv_file_name'], $ret_val);
echo 'last line: '.$last_line;
echo 'return values: '.$ret_val;

非常不清楚你想问什么。执行这个批处理脚本和PHP之间有什么联系?你是通过PHP调用它的吗?如果是,显示该部分。我已更新了我的question@04FS,我已经编辑了我的问题并更新了我的php脚本。请检查如何使用php将值传递给arg1、arg2?你能给我看一下示例代码吗?上面我已经用我正在使用的php脚本更新了我的问题?@jagad89I正在获取成功完成的命令。在浏览器上。但文件未复制到网络文件夹。您的文件名是否有空格?文件名中没有空格。但是当我在批处理文件上直接给出文件名时,它正在工作。它正在使用exec命令。不像下面的exec'C:\\scripts\batch1.bat.$\u GET['FILE\u NAME']这样的系统命令;
$last_line = system("cmd /c C:/path/to/bat/batchname.bat ".$_GET['csv_file_name'], $ret_val);
echo 'last line: '.$last_line;
echo 'return values: '.$ret_val;