You are here: Fax API > Fax Web Service > Code Samples > PHP Samples > Deprecated Samples > PHP4: How to fax a binary file
PHP Faxing Samples
- Tutorial: Fax from PHP
- Send a simple ASCII-text fax using SendCharFax
- Send one file attachment (e.g., PDF, DOC, HTML) to one recipient with Sendfax
- Fax one or more files to one or more recipients with SendfaxEx_2
- Get information about one or more submitted faxes with FaxStatusEx
- Get information about one or more submitted faxes with FaxQuery
- Get information about one or more submitted faxes with FaxQuery2
- Retrieve the image of a submitted fax with GetFaxImageResult
- Cancel a pending fax with CancelFax
- Inbound: get list of inbound faxes using GetList
- Inbound: retrieve a received fax using GetImageChunk
- Deprecated Samples
PHP4: How to fax a binary file
Faxing a binary file with PHP4
With thanks to Justin Horn from Justechnology, LLC
<? /** * Send a Fax using PHP/PEAR::SOAP Example: * - Using SendfaxEx() Method from InterFax Web Services */ /** * Your variables go here - assign a value to each one */ $username = ""; $password = ""; $faxnumber = ""; // formatted like +13055551234, i.e. +(country code)(area code)(phone number) $file = ""; // binary file to fax $filetype = ""; //e.g. HTML, DOC, PDF, etc.; see documentation for complete list $postponetime = ""; //e.g. 2001-04-25T20:31:00-04:00, use a past date/time to fax immediately $resolution = ""; // 0 for standard, 1 for fine $csid = ""; // your fax identifier, visible on the receiving machine's little screen $subject = ""; // for your reference, visible in the outbound queue $replyemail = ""; //optional address at which to receive an emailed confirmation /** * PEAR::SOAP class [http://pear.php.net/package/SOAP] */ require_once 'SOAP/Client.php'; // Open File if( !($fp = fopen($file, "r"))) { // Error opening file // Handle error how it is appropriate for your script exit; } // Read data from the file into $data $data = ""; while (!feof($fp)) $data .= fread($fp,1024); // URL path to InterFax Web Services $wsdl_url = 'http://ws.interfax.net/dfs.asmx?wsdl'; // Create an instance of the SOAP_WSDL class $WSDL = new SOAP_WSDL($wsdl_url); /** * This function creates a proxy to the SOAP services * so that you can access the InterFax methods directly * as if you were calling a local function */ $client = $WSDL->getProxy(); /** * Invoke the InterFax SendfaxEx Method * NOTE: 'base64_encode' is a native method in PHP [http://www.php.net/manual/en/function.base64-encode.php] */ $result = $client->SendfaxEx($username, $password, $faxnumber, base64_encode($data), $filetype, strlen($data), $postponetime, $resolution, $csid, $subject, $replyemail); // Echo Result if($result > 0) echo "Fax submitted. Transaction ID: $result"; else echo "Error sending fax. Return code: $result"; ?>