Sorry for the vague title, I don't use curl often enough to know what the proper terms are. Basically I'm trying to convert a commandline curl call that involves a file upload into a PHP script using curl_init etc.
The commandline curl has parameters like -F query='...' -F variables[file]=@/mnt/d/temp/test.jpg
. Calling the curl command via commandline works fine, so the backend is working. My issue is when I try it using PHP. My issue is I don't know how to properly convert that -F variables[file]=...
syntax into the PHP curl side.
Given that, I try this:
$query = '...';
$cFile = curl_file_create("/mnt/d/temp/test.jpg");
$variables = array("file" => $cFile);
$post = array('query' => $query,'variables' => $variables);
curl_setopt($chObj, CURLOPT_POSTFIELDS, $post);
Unfortunately, it returns HTTP 500.
I also try to replace the $cFile variable with $cFile = '@' . realpath("/mnt/d/temp/test.jpg");
, same result.
(This is also my first time uploading a file using PHP curl, my reference for the above code was this SO question: how to upload file using curl with php)
Any advice would be appreciated. (I would just Google it myself, but IDK the proper terms to Google.)