Closed Poyokos closed 6 years ago
Hello poyokos,
Can you ensure the file exists before upload?
if( !file_exists( 'upload/a.pdf' ) ) { die('woops'); }
We will check also if distinct exception is needed...
Yeah, i tried to put the if block but the issue still happening
The Code:
<?php
require_once('ilovepdf-php/init.php');
use Ilovepdf\UnlockTask;
echo file_exists('upload/a.pdf');
echo "<br>";
if(!file_exists('upload/a.pdf') ){
die('woops');
}
$myTask = new UnlockTask('my_public_key','my_secret_key');
$file = $myTask->addFile('upload/a.pdf');
$myTask->execute();
$myTask->download();
The Output:
1
Fatal error: Uncaught Ilovepdf\Exceptions\UploadException in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php:188 Stack trace: #0 C:\xampp\htdocs\unlock\ilovepdf-php\src\Task.php(154): Ilovepdf\Ilovepdf->sendRequest('post', 'upload', Array) #1 C:\xampp\htdocs\unlock\ilovepdf-php\src\Task.php(122): Ilovepdf\Task->uploadFile('qmpvzg6hqkAvk2r...', 'upload/a.pdf') #2 C:\xampp\htdocs\unlock\unlock.php(15): Ilovepdf\Task->addFile('upload/a.pdf') #3 {main} thrown in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php on line 188
I cannot reproduce your error (no message in exception) with any kind of uploaded file...
Can you give me the output of this?
<?php
require_once('ilovepdf-php/init.php');
use Ilovepdf\UnlockTask;
//with your credentils
$myTask = new UnlockTask('my_public_key','my_secret_key');
try{
$file = $myTask->addFile('upload/a.pdf');
}catch (\Ilovepdf\Exceptions\UploadException $e) {
echo "An error occured on upload: " . $e->getMessage() . " ";
var_dump($e->getErrors());
} catch (\Exception $e) {
echo "An error occured: " . $e->getMessage();
}
This is the output:
Notice: Trying to get property 'error' of non-object in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php on line 188 Notice: Trying to get property 'message' of non-object in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php on line 188 An error occured on upload: Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\unlock\unlock.php on line 11
Please try this:
<?php
require_once('ilovepdf-php/init.php');
use Ilovepdf\UnlockTask;
//with your credentils
$myTask = new UnlockTask('my_public_key','my_secret_key');
try{
$file = $myTask->addFile('upload/a.pdf');
} catch (\Exception $e) {
var_dump($e);
}
What's the output now?
The output:
Notice: Trying to get property 'error' of non-object in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php on line 188
Notice: Trying to get property 'message' of non-object in C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php on line 188 object(Ilovepdf\Exceptions\UploadException)#6 (9) { ["params":"Ilovepdf\Exceptions\ExtendedException":private]=> NULL ["type":"Ilovepdf\Exceptions\ExtendedException":private]=> NULL ["message":protected]=> string(0) "" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(0) ["file":protected]=> string(52) "C:\xampp\htdocs\unlock\ilovepdf-php\src\Ilovepdf.php" ["line":protected]=> int(188) ["trace":"Exception":private]=> array(3) { [0]=> array(6) { ["file"]=> string(48) "C:\xampp\htdocs\unlock\ilovepdf-php\src\Task.php" ["line"]=> int(154) ["function"]=> string(11) "sendRequest" ["class"]=> string(17) "Ilovepdf\Ilovepdf" ["type"]=> string(2) "->" ["args"]=> array(3) { [0]=> string(4) "post" [1]=> string(6) "upload" [2]=> array(3) { ["task"]=> string(154) "h2x0dfwjtkrhtrdm6hfrq2rnyq6gjdwhlqndyznw8sfz22mtzn709AA31rhtxl18tcs0w82cbyn9lrvwnzqfbg1Av7p24tzlck07qwbc50clfAt4thcdyj19wzzd13tntpd129w4kr9jymtp894xhwnyhq" ["v"]=> string(10) "php.1.1.10" ["file"]=> object(CURLFile)#4 (3) { ["name"]=> string(12) "upload/a.pdf" ["mime"]=> string(0) "" ["postname"]=> string(0) "" } } } } [1]=> array(6) { ["file"]=> string(48) "C:\xampp\htdocs\unlock\ilovepdf-php\src\Task.php" ["line"]=> int(122) ["function"]=> string(10) "uploadFile" ["class"]=> string(13) "Ilovepdf\Task" ["type"]=> string(2) "->" ["args"]=> array(2) { [0]=> string(154) "h2x0dfwjtkrhtrdm6hfrq2rnyq6gjdwhlqndyznw8sfz22mtzn709AA31rhtxl18tcs0w82cbyn9lrvwnzqfbg1Av7p24tzlck07qwbc50clfAt4thcdyj19wzzd13tntpd129w4kr9jymtp894xhwnyhq" [1]=> string(12) "upload/a.pdf" } } [2]=> array(6) { ["file"]=> string(33) "C:\xampp\htdocs\unlock\unlock.php" ["line"]=> int(7) ["function"]=> string(7) "addFile" ["class"]=> string(13) "Ilovepdf\Task" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> string(12) "upload/a.pdf" } } } ["previous":"Exception":private]=> NULL }
Hello @Poyokos maybe can be a problem of timeout while uploading the file. Getting a 0 as a response code is not the API who sends this code, so this is likely some connection problem or timeout.
Best regards
C:\xampp\htdocs\pdftest\index.php:43: object(Ilovepdf\Exceptions\UploadException)[4] private 'params' (Ilovepdf\Exceptions\ExtendedException) => null private 'type' (Ilovepdf\Exceptions\ExtendedException) => null protected 'message' => string 'Upload error' (length=12) private 'string' (Exception) => string '' (length=0) protected 'code' => int 0 protected 'file' => string 'C:\xampp\htdocs\pdftest\src\Ilovepdf.php' (length=40) protected 'line' => int 191 private 'trace' (Exception) => array (size=3) 0 => array (size=6) 'file' => string 'C:\xampp\htdocs\pdftest\src\Task.php' (length=36) 'line' => int 191 'function' => string 'sendRequest' (length=11) 'class' => string 'Ilovepdf\Ilovepdf' (length=17) 'type' => string '->' (length=2) 'args' => array (size=3) ... 1 => array (size=6) 'file' => string 'C:\xampp\htdocs\pdftest\src\Task.php' (length=36) 'line' => int 156 'function' => string 'uploadFile' (length=10) 'class' => string 'Ilovepdf\Task' (length=13) 'type' => string '->' (length=2) 'args' => array (size=2) ... 2 => array (size=6) 'file' => string 'C:\xampp\htdocs\pdftest\index.php' (length=33) 'line' => int 41 'function' => string 'addFile' (length=7) 'class' => string 'Ilovepdf\Task' (length=13) 'type' => string '->' (length=2) 'args' => array (size=1) ... private 'previous' (Exception) => null public 'xdebug_message' => string '
<?php require_once('init.php'); use Ilovepdf\UnlockTask; //with your credentils $myTask = new UnlockTask('',''); try{ $file = $myTask->addFile('Bt21to27july2019.pdf'); } catch (\Exception $e) { var_dump($e); } ?>
Same problem, cant fix it
Hello mark, can you write us the exception?
I had the same problem and I could solve it by changing the file path
At the beginning I had written this part like this: $file = $myTask->addFile('../path/file.pdf');
Then I changed it this way: $file = $myTask->addFile('C:/xampp/htdocs/path/path/file.pdf');
And it worked, I don't know the reason but if it gives you the same problem you can try it
I had the same problem and I could solve it by changing the file path
- At the beginning I had written this part like this: $file = $myTask->addFile('../path/file.pdf');
- Then I changed it this way: $file = $myTask->addFile('C:/xampp/htdocs/path/path/file.pdf');
And it worked, I don't know the reason but if it gives you the same problem you can try it
If you are running from a server (or xampp), you should use addFileFromUrl() instead addFile(). It worked for me.
Thanks For the Help Bubex
Thanks, Regards Shivek Sahay
On December 5, 2019 at 20:13 GMT, Bubex notifications@github.com wrote:
I had the same problem and I could solve it by changing the file path
And it worked, I don't know the reason but if it gives you the same problem you can try it
If you are running from a server (or xampp), you should use addFileFromUrl() instead addFile(). It worked for me.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.
I'm trying to unlock a pdf file but when I do the task it gives me this issue:
This is my code:
I used a try-catch block, but the exception message was empty.