dq13733519262 2018-04-08 16:03 采纳率: 0%
浏览 71


I have a web application that I need to send a CURL command from a HTTP URL to an application which is running on Ubuntu.

The curl command is this:

curl -X POST --data-binary @/home/User/Pastec_FYP/Currency_Test_Images/Test_TenEuro.jpg

The command is getting an image from the following:


And it is searching through the index at

I need to be able to translate that to PHP.


This is what I got so far, but it's still saying image_not_decoded

$ch = curl_init();

$post = array(
    "file" => "@" .realpath("/home/User/Pastec_FYP/Currency_Test_Images/Test_TenEuro.jpg")

    $ch, array( 
    CURLOPT_URL => '',
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post),

$output = curl_exec($ch);
echo $output;

From past use of the physical Curl command in Ubuntu it used to return that error when the path to the Image wasn't right, but i know its right as it works in Command line.

So is there anything I should change?

Additional Edit (To get it working)

I got it working how I wanted, but probably a lot more long winded than needed, but it works. I wrote a CurlCommand.sh with the Curl command I wanted to execute, then called the .sh file from a batch script (CallCurlCommand.bat) opening Ubuntu and inserting the CurlCommand.sh into it. Then using PHP to call the batch file (CallCurlCommand.bat).


curl -X POST --data-binary '@/home/User/Pastec_FYP/Currency_Test_Images/Test_FiveEuro.jpg' 'http://localhost:4212/index/searcher'


C:\Users\User\AppData\Local\Microsoft\WindowsApps\ubuntu.exe< C:\Users\User\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalStateootfs\home\User\Pastec_FYP\CurlCommand.sh



I do still wish there was a straight conversion to PHP but this works.

  • 写回答

1条回答 默认 最新

  • dreinuqm992401 2018-04-10 18:59

    It seems you have bit of a special system - you seem to be running your server on windows, which has ubuntu as a subsystem and curl as well as your file which you post is in there.

    If you want to run it directly from your PHP server, you could install curl on your Windows. One way of doing it is downloading Win32 binary of curl from https://curl.haxx.se/download.html. After that you should be able to do something like

    $curlpath = 'C:\path\to\curl.exe';
    $filepath = '/home/User/FYP_Pastec/Currency_Test/Test_FiveEuro01.jpg';
    $url = 'http://localhost:4212/index/searcher';
    exec("$curlpath -X POST --data-binary \"@$filepath\" \"$url\"");

    which would then send it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 关于#ar#的问题:/* User can add his own implementation to report the HAL error return state */(语言-c语言)
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败