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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题