I really would like to use ABBYY OCR, but I can't get it to work! I when ever I run the code below on my Apache server, running PHP 5, I get this:

Fatal error: Call to a member function attributes() on a non-object in /home/content/76/7290476/html/dumbocr/abbyy_php_example.php on line 36

This is my PHP code:

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

// !!!!!!!!!! Enter your data here !!!!!!!!!! $applicationId = 'DumbDrive'; $password = '===password-here===='; $fileName = 'dselogo3.png';

// Get path to file that we are going to recognize $local_directory=dirname(FILE).'';

// 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';

// Send HTTP POST request and ret xml response $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password"); curl_setopt($ch, CURLOPT_POST, 1); $post_array = array( "my_file"=>"@".$local_directory.$fileName, ); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); $response = curl_exec($ch); curl_close($ch);

// 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); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url.$qry_str); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password"); $response = curl_exec($ch); curl_close($ch);

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

} while($arr["status"] != "Completed");

// Result is ready. Download it

$url = $arr["resultUrl"];
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); curl_close($ch);

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

asked 20 May '12, 00:36

dumbproducts's gravatar image


closed 19 Jun '12, 16:06

Vasily%20Panferov's gravatar image

Vasily Panferov ♦♦

The question has been closed for the following reason "Problem is not reproducible or outdated" by Vasily Panferov 19 Jun '12, 16:06

It seems that there was a minor error in the PHP code sample: path to the image file being sent to OCR Engine was stated incorrectly. You'll need to add a forward slash between the directory and the filename variables on line 28:


I've sent the working code to your email. We'll update the codesamples in our documentation shortly. Please let me know if you have any additional questions.


answered 22 May '12, 11:39

Nikolay_Kh's gravatar image

Nikolay_Kh ♦♦

According to the error you receive, you have something wrong with $arr variable. Try the following:

  1. Check the login credentials you use (they were sent to your email). I've checked sdk server log for your application, there were no HTTP calls from you.

  2. echo out the $response var and print_r the $xml object above. What are their values?

  3. Try running echo function_exists(simplexml_load_string); on your server to make sure you can parse xml the way it is proposed in the example.

  4. Check that the dselogo3.png is in the same directory with the abbyy_php_example.php file.

If this won't help, please send the code you use (within a php file, so the code structure would be preserved) to cloudocrsdkbeta@abbyy.com

Please let me know if you could work it out!


answered 21 May '12, 12:29

Nikolay_Kh's gravatar image

Nikolay_Kh ♦♦

edited 22 May '12, 11:40

Hi Nikolay,

I'm having the same prb as Andrey above. I double check the above items and here are the results:

  1. I should have valid login credentials (I will email my code to you)
  2. I echo and print_r both $response and $xml, they do not show any value.
  3. function simplexml_load_string is valid on my server
  4. the image is the same directory with my script file.

answered 30 May '12, 15:15

swiftwolff's gravatar image


Did you check a forward slash between the directory and the filename variables mentioned in the accepted answer?

(30 May '12, 15:18) Nikolay_Kh ♦♦

Please check your $local_directory variable. In the code you provided it has an /images/ subfolder, so you have to either create this folder and place an image in it or remove it from the variable. Note that in this question there's no such folder in the image path.

(30 May '12, 16:08) Nikolay_Kh ♦♦

Follow this question

By Email:

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



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



Asked: 20 May '12, 00:36

Seen: 3,531 times

Last updated: 19 Jun '12, 16:06

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