使用CURL命令的批处理文件在PHP中无法正确执行,但是从命令行

时间:2017-03-24 11:43:49

标签: php batch-file curl

您好我在批处理文件中运行curl命令时遇到问题。我从PHP代码执行文件,如下所示:

exec("curlPut.bat $zipName $url", $output);

在运行批处理文件之前,我将PHP代码中的目录更改为批处理文件和zip所在的位置。

这是剧本:

@echo off
curl -X PUT -H "Content-Type:application/zip" --data-binary @%1 %2

然而,当我检查url时,PUT命令是要发送zip文件,数据不存在。

当我在Windows cmd中运行完全相同的脚本时,它可以很好地工作。

curlPut.bat zipFile.zip http://exampleurl

这是使用我在PHP代码中作为参数传递的完全相同的数据,无法找出为什么批处理文件适用于一个而不是另一个可以帮助任何人?

3 个答案:

答案 0 :(得分:1)

我不知道如何在php中转义双引号,但你应该这样做。

exec("curlPut.bat $zipName \"$url\"", \"$output\");

在批次报价中,避免双重报价:

@echo off
Echo %~nx0 Arg1:[%1]
Echo %~nx0 Arg2:[%2]
curl -X PUT -H "Content-Type:application/zip" --data-binary @"%~1" "%~2"
pause

答案 1 :(得分:1)

您可能无法直接执行bat文件,而是必须使用cmd.exe解释器。

请参阅https://stackoverflow.com/a/835955/370052

$ output显示出什么? 您还可以向exec()添加$ err变量以检查退出代码。

答案 2 :(得分:-1)

批量<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="wtw.sunonetaji.landing.MainScreenListActivity"> <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:id="@+id/activity_main_screen_list" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="wtw.sunonetaji.landing.MainScreenListActivity"> <include android:id="@+id/toolbar" layout="@layout/toolbar" /> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="vertical" /> </LinearLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/fab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" android:layout_margin="16dp" app:backgroundTint="@color/bgcoloor" android:clickable="true" android:padding="10dp" android:src="@drawable/pencileditbutton" app:borderWidth="1dp" /> </android.support.design.widget.CoordinatorLayout></RelativeLayout> 中的变量不是%variable%