0

I want to use Composer's PHP wrapper to upload an image to CloudConvert. This image will come from a html form which users will fill. In the array that CloudConvert's start() function uses to upload a file, the key/value pair for an image file is:

    <?php
    $process->start([
        "input" => "download",

        "file" => "http://url/to/my/file.ext",

        "outputformat" => "png",
        ......
        ......

        ],
    ]);
    ?>

The value associated with the 'file' key seems as if it must be a public URL. Ideally I would like to use the html form variable as the value for the 'file' key in the array. I've tried using the $_FILES array with both ['tmp_name] and ['name'] but both throw errors. I've also placed an image in the root directory and then used $img_filepath = fopen('./Post_box_Lake_District.jpg', 'r'); but that throws the following error: Uncaught CloudConvert\Exceptions\ApiException: Upload is not allowed in this process state in C:\xampp\htdocs\test_site\vendor\cloudconvert\cloudconvert-php\src\Process.php:80. I presume I could use the URLs for images stored on a file on my server but for the moment I'm storing images in a database. CloudConvert have a facility where users can upload their API but, if possible, I don't want to do that. I want everything to come through my server. So how can I upload images via CloudConvert's API. Thanks for any help in advance.

  • "for the moment I'm storing images in a database"...that doesn't stop there being a unique URL which would return that image when a request was made to it, e.g. `http://yourdomain.com/getimage.php?id=20` or something – ADyson Jan 02 '20 at 15:42
  • If I understand you correctly you're saying: _having inserted a user uploaded image in my database use as a url, the example you've provided, where getimage.php contains a select statement that will pull image with id 20 from the database?_ – code-slightly-red Jan 02 '20 at 20:11
  • that's exactly what I mean, yes – ADyson Jan 02 '20 at 21:49
  • Thank you very much. Your suggestion is exactly what I want. I don't know how I can publicly accept you answer though. If you're interested, I have asked, as a follow on from your answer here, a seperate question: _How is the output of a php script made to be the resource of the URL that contains the script_ . It has question number 59585467. – code-slightly-red Jan 03 '20 at 21:23

0 Answers0