PHP Fax - Send a fax with a large file

This is a more advanced PHP code sample to show how to send a fax with a large document. This code sample is based on the PHP library for InterFAX available on Github.

This sample demonstrates how to upload a large file to InterFAX using the Document component and then sending a fax to a single recipient while referencing that previously uploaded file - all you need to do in order to change it is to provide a different fax number and a different path to the files that you would like to send. You can also change the size of the chunk that you will be uploading the file with.

  
     // read the file to send
$stream = fopen('test.pdf', 'rb');

// create a new InterFAX Document
$document = $interfax->documents->create(
  'test.pdf',
  filesize('test.pdf')
);

// upload each chunk
$current = 0;
while (!feof($stream)) {
    $chunk = fread($stream, 500);
    $end = $current + strlen($chunk);
    // upload a specific chunk
    echo ".";
    $document->upload($current, $end-1, $chunk);
    $current = $end;
}
fclose($stream);

// send the fax
$interfax->deliver([
  // a valid fax number
  'faxNumber' => '+11111111112',
  // the document URI
  'file' => $document->getHeaderLocation()
]);

  

You can check on the status of this fax by following this sample code.

Contact us today

Talk to a member of our team about the benefits InterFAX can bring to your organization's communications processes.

Contact us today