phprequireautoloadcloudconvert

How to use CloudConvert API


I'm trying to upload an image to CloudConvert, using a PHP wrapper, for format conversion. My short test html/php code is:

<html>
<body>
//html form...
<?php 

require __DIR__ . '/vendor/autoload.php';
use \CloudConvert\Api;

$api = new Api("*********");
//various $process objects

?>

When I hit the form Submit button I get the following errors.

Warning: require(C:\xampp\htdocs\test_site/vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\test_site\REST_test.php on line 14

Fatal error: require(): Failed opening required 'C:\xampp\htdocs\test_site/vendor/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\test_site\REST_test.php on line 14

I'm a novice at this and simply do not understand how the require and use statements - which I copied from CloudConvert's API docs - actually work in the context uploading a file to a webservice. I can't see how they provide any kind of path to CloudConvert's site and don't understand the error messages. It would be great if anybody can throw some light on this. Thanks in advance for any help.


Solution

  • This error message means that PHP can't find the file you're telling it to load. There are two likely problems:

    1. Your package uses Composer but you haven't run composer install to download dependencies (which generates the vendor subdir.)
    2. Since __DIR__ expands to the directory that the current file is in, your code is probably in an adjacent subdir like src -- which means you'll need to traverse up a directory first, something like: require __DIR__ . '/../vendor/autoload.php';