Fatal error: Call to a member function attributes() on a non-object in "path of file"... I see a solution for this same problem in june but the that i'm using is updated but not work anyway.

Help me please someone...

Below my code:

// 1. Send image to Cloud OCR SDK using processImage call // 2. Get response as xml // 3. Read taskId from xml

//!!! Please provide your application id and password and remove this line !!! // Name of application you created $applicationId = 'myidapp'; // Password should be sent to your e-mail after application was created $password = 'mypassword'; $fileName = 'harry.png';

// Get path to file that we are going to recognize $local_directory=dirname(FILE).'/images/'; $filePath = $local_directory.'/'.$fileName; if(!file_exists($filePath)) { die('File '.$filePath.' not found.'); }

// Recognizing with English language to rtf // You can use combination of languages like ?language=english,russian or // ?language=english,french,dutch // For details, see API reference for processImage method $url = 'http://cloud.ocrsdk.com/processImage?language=english,portuguese&exportFormat=rtf';

// Send HTTP POST request and ret xml response $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlHandle, CURLOPT_USERPWD, "$applicationId:$password"); curl_setopt($curlHandle, CURLOPT_POST, 1); $post_array = array( "my_file"=>"@".$filePath, ); curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $post_array); $response = curl_exec($curlHandle); if($response == FALSE) { $errorText = curl_error($curlHandle); curl_close($curlHandle); die($errorText); } curl_close($curlHandle);

// Parse xml response $xml = simplexml_load_string($response); $arr = $xml->task[0]->attributes();

// Task id $taskid = $arr["id"];

// 4. Get task information in a loop until task processing finishes // 5. If response contains "Completed" staus - extract url with result // 6. Download recognition result (text) and display it

$url = 'http://cloud.ocrsdk.com/getTaskStatus'; $qry_str = "?taskid=$taskid";

// Check task status in a loop until it is finished // TODO: support states indicating error do { sleep(5); $curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url.$qry_str); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlHandle, CURLOPT_USERPWD, "$applicationId:$password"); $response = curl_exec($curlHandle); curl_close($curlHandle);

// parse xml $xml = simplexml_load_string($response); $arr = $xml->task[0]->attributes(); } while($arr["status"] != "Completed");

// Result is ready. Download it

$url = $arr["resultUrl"];
$curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); // Warning! This is for easier out-of-the box usage of the sample only. // The URL to the result has https:// prefix, so SSL is required to // download from it. For whatever reason PHP runtime fails to perform // a request unless SSL certificate verification is off. curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curlHandle); curl_close($curlHandle);

// Let user donwload rtf result header('Content-type: application/rtf'); header('Content-Disposition: attachment; filename="file.rtf"'); echo $response; ?>

asked 13 Dec '12, 18:04

Paulo%20Cesar's gravatar image

Paulo Cesar
111

Which line of code specifically yields the error message?

(14 Dec '12, 11:45) Dmitry Me ♦♦

The erro is on line 52

(14 Dec '12, 14:51) Paulo Cesar

Since you don't specify where you got the source from and when could you please highlight the actual code instead of the line number? I.e. here https://github.com/abbyysdk/ocrsdk.com/blob/master/PHP/abbyy_php_example.php line 51 is $taskid = $arr["id"]; and lines are not numbered in the code you posted.

(14 Dec '12, 17:52) Dmitry Me ♦♦

on line 48 - $arr = $xml->task[0]->attributes();

tks 4 ur help

(14 Dec '12, 17:57) Paulo Cesar

Something is wrong with $response variable value. What value does it hold at that moment?

(14 Dec '12, 18:23) Dmitry Me ♦♦

the $response receive this value

$url = 'http://cloud.ocrsdk.com/processImage?language=english,portuguese&exportFormat=rtf';

in this "function":

$curlHandle = curl_init(); curl_setopt($curlHandle, CURLOPT_URL, $url); curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlHandle, CURLOPT_USERPWD, "$applicationId:$password"); curl_setopt($curlHandle, CURLOPT_POST, 1);

(14 Dec '12, 19:19) Paulo Cesar

That's unclear. What output do you get if you add echo $response; right before $arr = $xml->task[0]->attributes(); line?

(14 Dec '12, 19:42) Dmitry Me ♦♦

uhm... get me this mensage:

Unknown language portuguese

I don't know about that this API no have support to portuguese? I'll tri just englisn and say to you what sample return

(14 Dec '12, 19:48) Paulo Cesar

works, realy no have support to portuguese

(14 Dec '12, 19:50) Paulo Cesar

@PauloCesar: You can specify either PortugueseBrazilian or PortigueseStandard. Full list of languages is available at http://ocrsdk.com/documentation/specifications/recognition-languages/

(17 Dec '12, 11:13) Dmitry Me ♦♦
showing 5 of 10 show 5 more comments
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×100
×1

Asked: 13 Dec '12, 18:04

Seen: 5,214 times

Last updated: 17 Dec '12, 11:13

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal