\n"); exit(64); } $url = $argv[1]; $filePath = $argv[2]; if (!is_file($filePath) || !is_readable($filePath)) { fwrite(STDERR, "File is not readable: {$filePath}\n"); exit(66); } $upload = new CURLFile($filePath, 'text/plain', basename($filePath)); $fields = [ 'user_id' => '42', 'description' => 'Profile fixture', 'avatar' => $upload, ]; $curl = curl_init($url); if ($curl === false) { fwrite(STDERR, "Could not initialize cURL.\n"); exit(1); } curl_setopt_array($curl, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields, CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => [ 'Accept: application/json', ], CURLOPT_TIMEOUT => 15, ]); $response = curl_exec($curl); if ($response === false) { fwrite(STDERR, 'cURL error: ' . curl_error($curl) . PHP_EOL); curl_close($curl); exit(1); } $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl); echo "HTTP status: {$status}" . PHP_EOL; echo $response; if ($status < 200 || $status >= 300) { exit(1); }