# Curl command in php to post LUA commands

**URL:** https://discourse.orthanc-server.org/t/curl-command-in-php-to-post-lua-commands/2514
**Category:** Google Groups archive
**Created:** [July 6, 2021, 5:18pm UTC](https://discourse.orthanc-server.org/t/curl-command-in-php-to-post-lua-commands/2514 "2021-07-06T17:18:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Julio\_Cesar\_Luciano](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/j/50afbb/32.png) [@Julio\_Cesar\_Luciano](https://discourse.orthanc-server.org/u/Julio_Cesar_Luciano)
#### Post date: [July 6, 2021, 5:18pm UTC](https://discourse.orthanc-server.org/t/curl-command-in-php-to-post-lua-commands/2514/1 "2021-07-06T17:18:29Z")

</div>

Hi, I’m trying to play a POST command to a lua script, but I get a “bool(false)” response on my system, any help on what’s wrong?  
$ curl -X POST [http://localhost:8042/tools/execute-script](http://localhost:8042/tools/execute-script) --data-binary @script.lua

\<?php $orthanc = "http://localhsot:8042/"; $url = $orthanc.'/tools/execute-script'; $uploadFilePath = \_\_DIR\_\_ . '/script.lua'; //$uploadFilePath="@$file[tmp\_name]"; if (!file\_exists($uploadFilePath)) { throw new Exception('File not found: ' . $uploadFilePath); } $uploadFileMimeType = mime\_content\_type($uploadFilePath); $uploadFilePostKey = 'file'; $uploadFile = new CURLFile( $uploadFilePath, $uploadFileMimeType, $uploadFilePostKey ); $curlHandler = curl\_init(); curl\_setopt\_array($curlHandler, [CURLOPT\_URL =\> $url, CURLOPT\_RETURNTRANSFER =\> true, /\*\* \* Specify POST method \*/ CURLOPT\_POST =\> true, /\*\* \* Specify array of form fields \*/ CURLOPT\_POSTFIELDS =\> [ $uploadFilePostKey =\> $uploadFile,], ]); $response = curl\_exec($curlHandler); curl\_close($curlHandler); echo($response);

---

<div class="post-metadata">

### Author: ![jodogne](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/jodogne/32/1511_2.png) [@jodogne](https://discourse.orthanc-server.org/u/jodogne)
#### Post date: [July 6, 2021, 5:57pm UTC](https://discourse.orthanc-server.org/t/curl-command-in-php-to-post-lua-commands/2514/2 "2021-07-06T17:57:25Z")

</div>

Hello,

You should _not_ use “CURLFile()” as the argument to “CURLOPT\_POSTFIELDS”.

Instead, the “CURLOPT\_POSTFIELDS” must simply contain a plain string containing your Lua script. For instance:

[https://stackoverflow.com/a/871445/881731](https://stackoverflow.com/a/871445/881731)

Also, make sure that the configuration option “ExecuteLuaEnabled” of Orthanc is set to “true”:  
[https://book.orthanc-server.com/users/configuration.html](https://book.orthanc-server.com/users/configuration.html)

---

<div class="post-metadata">

### Author: ![Julio\_Cesar\_Luciano](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/j/50afbb/32.png) [@Julio\_Cesar\_Luciano](https://discourse.orthanc-server.org/u/Julio_Cesar_Luciano)
#### Post date: [July 6, 2021, 7:23pm UTC](https://discourse.orthanc-server.org/t/curl-command-in-php-to-post-lua-commands/2514/3 "2021-07-06T19:23:04Z")

</div>

Thanks Sebastian , I’ve changed my code to the following structure: although it’s not clear to me if it’s really pure script injection, or if I have to have a file, my system still doesn’t work.

This has been confirmed: “ExecuteLuaEnabled” of Orthanc is set to “true”

\<?php $orthanc = "[http://localhsot:8042/](http://localhsot:8042/)"; $url = $orthanc.'tools/execute-script'; //echo $url; .... $curl = curl\_init($url); curl\_setopt($curl, CURLOPT\_URL, $url); curl\_setopt($curl, CURLOPT\_POST, true); curl\_setopt($curl, CURLOPT\_RETURNTRANSFER, true); $headers = array( "Content-Type: application/x-www-form-urlencoded", ); curl\_setopt($curl, CURLOPT\_HTTPHEADER, $headers); //script lua $data = "function OnStoredInstance(instanceId, tags, metadata) if tags['Modality'] == 'DX' then SendToModality(instanceId, 'gepacs') end if tags['Modality'] == 'MR' then SendToModality(instanceId, 'gepacs') end if tags['Modality'] == 'CT' then SendToModality(instanceId, 'gepacs') end end"; curl\_setopt($curl, CURLOPT\_POSTFIELDS, $data); //for debug only! curl\_setopt($curl, CURLOPT\_SSL\_VERIFYHOST, false); curl\_setopt($curl, CURLOPT\_SSL\_VERIFYPEER, false); $resp = curl\_exec($curl); curl\_close($curl); var\_dump($resp); ?\>
