0

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.

Muhammad Dyas Yaskur
  • 6,914
  • 10
  • 48
  • 73

1 Answers1

0

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';
Alex Howansky
  • 50,515
  • 8
  • 78
  • 98
  • When you say "Your package uses Composer.." do you mean that CloudConvert expect me to have Composer installed on localhost (which is where I'm testing my code)? I don't actually have composer installed and I don't understand how Composer on my machine can 'make the connection' between my script and ClodConvert's API. You probably need to go past 'APIs for dummies' and go into 'explain like I'm five' mode in order to explain this to me. By the way I have require __DIR__ in my code. Thanks! – code-slightly-red Dec 26 '19 at 20:24
  • If there is a file named `composer.json` in the top-level directory of the project, then it uses Composer to manage dependencies like helper libraries. If this is the case, then you'll need to [install Composer](https://getcomposer.org/doc/00-intro.md) if it's not already installed, and then run `composer install` to install the dependencies. – Alex Howansky Dec 26 '19 at 20:31
  • I don't know what is meant by 'the top level directory of the project'. I have html, php, javascript and css file in a directory and composer.json is nowhere in that or any other directory. I'm not using any kind of framework, which I think is what is implied by the word 'project'. – code-slightly-red Dec 26 '19 at 20:42
  • If you copied a line containing `vendor/autoload.php` from their docs, then they are expecting you to use Composer. If you did not download a `composer.json` from them as part of a package, then you probably missed a step in the docs that instructs you to run something like `composer require "some/package"`. – Alex Howansky Dec 26 '19 at 20:46
  • Also, I don't know what is meant by dependencies in this context. – code-slightly-red Dec 26 '19 at 20:49
  • CloudConvert provides a library of PHP helper code (i.e., a dependency) that you can use to hit their API. They've already done most of the programming work for you. The example you copied assumes that you have this library installed, but you do not have have it installed. To install it, first install Composer as previously noted, then run `composer require cloudconvert/cloudconvert-php` while in the directory where your PHP file is. – Alex Howansky Dec 26 '19 at 20:54
  • Perhaps disregard the rest of this comment; I wrote it while before seeing your last comment. But the fog is lifting now. I will do what you said and see what happens and get back to you tomorrow. I'm in central Europe and it's late and I'm very tirer. Thank you very much for your help!!!. I didn't download a package. I simply copied and pasted the require __DIR__ line, the use line, the new Api(***) , $process = $api->createProcess([..]); $process->start([]); $process->upload(fopen()); and $process->download(); with some arguments in each. I'm sorry to be making such heavy weather of this. – code-slightly-red Dec 26 '19 at 20:57
  • Please read that last comment again. I've given you everything you need. – Alex Howansky Dec 26 '19 at 20:59
  • I think you have. Thanks a lot!! – code-slightly-red Dec 26 '19 at 21:03
  • I'd make this the accepted answer if I had the points but I don't. I learned from it and was able to move forward. – code-slightly-red Dec 27 '19 at 17:57
  • You don't need points to mark an answer accepted. _"When you have decided which answer is the most helpful to you, mark it as the accepted answer by clicking on the check box outline to the left of the answer."_ *Awarded at: 1 reputation* – Alex Howansky Dec 29 '19 at 20:24