2

Analyze a file

scanfile

POST https://facturalex.com/api/v1/scanfile?login=&password=

loginYour identification code.
passwordYour password.
multipart/form-data
fileContent of the PDF in binary.

NOTE: 1 operation of analysis of a document costs 1 credit.

$ curl -D - -X POST "https://facturalex.com/api/v1/scanfile?login=abcdef&password=ABCDEF" -F "file=@file.pdf"

NOTE: The service only accepts a PDF file.

Download the code of the sendpost and file_mime_type functions from the iZend library. Copy the files in the space of your application.

NOTE: See the page Call the service API for a description of the sendpost and file_mime_type functions.

Add the file scanfile.php with the following content:

  1. require_once 'sendhttp.php';
  2. require_once 'filemimetype.php';

Charge le code des fonctions sendpost et file_mime_type.

  1. function scanfile($login, $password, $file) {

Defines the function scanfile. $login is your identification code. $password is your password. $file is the pathname of the PDF file to validate.

  1.     $curl = 'https://facturalex.com/api/v1/scanfile' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);

Sets $curl to the URL of the scanfile action with the identification code and the password of the user's account. $login and $password must be escaped.

  1.     $files=array('file' => array('name' => basename($file), 'tmp_name' => $file, 'type' => file_mime_type($file)));

Prepares the list of files attached to the POST: file - the PDF to scan with the name of the file, the pathname of the file and its MIME type.

  1.     $response=sendpost($curl, false, $files);

Sends the HTTP request with sendpost. The arguments login and password are already in $curl.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

If $response is false, the server is unreachable. If $response[0] doesn't contain the HTTP return code 200 Ok, an execution error has occurred. In case of error, scanfile returns false.

  1.     $r=json_decode($response[2], true);

Decodes the data returned in JSON.

  1.     if ($r['status'] == 'success') {
  2.         return $r['data']['message_text'];
  3.     }

Returns the text of the analysis of the document.

  1.     return false;
  2. }

Returns false in case of error.

EXAMPLE

Assuming you have saved the files sendhttp.php, filemimetype.php and scanfile.php in the current directory, run PHP in interactive mode, load the scanfile function and call it with your identification code and password, the pathname of a PDF in argument:

$ php -a
php > require_once 'scanfile.php';
php > $s=scanfile('abcdef', 'ABCDEF', 'file.pdf');
php > file_put_contents('analysis.txt', $s);
php > quit

Display the text of the analysis:

$ cat analysis.txt

Call the service API, Check your credit

Comments

To add a comment, click here.