ilovepdf / ilovepdf-php

iLovePDF Rest Api - PHP Library (https://developer.ilovepdf.com)
147 stars 39 forks source link

[Solved] couldn't open file #4

Closed taqhiz closed 7 years ago

taqhiz commented 7 years ago

Hi, I'm trying to use your API but I have an issue, to add file to Task, It returns me a Message error like this..

An error occured: couldn't open file "uploads/_2017_08_10_08_24_55_Circular_12.pdf"

This is how I'm executing in my PHP.

$carpeta = "uploads/"; opendir($carpeta); $destino = $carpeta.$_FILES['pdf']['name']; copy($_FILES['pdf']['tmp_name'], $destino); try { $myTaskCompress = new CompressTask('project_public_0bbf', 'secret_key_01f'); $myTask = $myTaskCompress->newTask('split'); $file1 = $myTaskCompress->addFile($destino); $myTaskCompress->execute(); $myTaskCompress->download(); } catch (\Ilovepdf\Exceptions\StartException $e) { echo "An error occured on start: " . $e->getMessage() . " "; // Authentication errors } catch (\Ilovepdf\Exceptions\AuthException $e) { echo "An error occured on auth: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Uploading files errors } catch (\Ilovepdf\Exceptions\UploadException $e) { echo "An error occured on upload: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Processing files errors } catch (\Ilovepdf\Exceptions\ProcessException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Downloading files errors } catch (\Ilovepdf\Exceptions\DownloadException $e) { echo "An error occured on process: " . $e->getMessage() . " "; echo implode(', ', $e->getErrors()); // Other errors (as connexion errors and other) } catch (\Exception $e) { echo "An error occured: " . $e->getMessage(); }

SOLVED!

I managed to resolve the issue replacing this line:

$file1 = $myTaskCompress->addFile($destino);

For this one 👍

$file = $myTaskCompress->addFile(dirname(__FILE__)."/".$destino);

Extra

And for complete the download I edited this line...

$myTaskCompress->download("uploads/");

This replace the PDF previously uploaded for the compressed PDF.

maztch commented 7 years ago

This exception says the file doesn't exists. Try this before add:

if(!file_exists($destino)){
    throw new \Exception('this file: '.$destino.' not exists');
}

And check the $destino content, to verify the path.

taqhiz commented 7 years ago

Yes, that was the error, I managed to resolve the error.

Post updated.