Hylafax Mailing List Archives

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [hylafax-users] Web faxing



On Wednesday 01 Feb 2006 01:21, Paul Daly wrote:
> Hi all, just wondering if anybody has tried my scenario and if there is an
> easy fix.
>
> I have 2 servers, one which has just been set up as a fax server that we
> are trialling HylaFax with, the other is a web server at a different
> location but on the same WAN.
>
> We have a php based application that has been developed in-house that we
> wish to add fax capability to, at the moment we have them printing from a
> pdf produced from the program and then manually faxing it.
>
> Has anybody tried this or can anyone think of any way to do this, both
> machines are running linux.

Yes, it's very easy to do this.  You just need to know about the `backtick` 
operator syntax.  If you do something like

$files = `ls`;

then "ls" will be passed to a shell; and when the command is finished the PHP 
variable $files will contain whatever the command sent to STDOUT.  Note that, 
exactly like "speech marks", variables within `backticks` will be 
substituted.  So you can do things like

$files = `ls $dir`

Note that if an error occurs with the command, then the error messages will go 
to STDERR  {which goes nowhere when you use the `backticks` operator}  and 
not STDOUT  {when you are using a terminal, of course, STDOUT and STDERR both 
go to the screen};  so you probably want to append 2>&1 just to make sure you 
will get the text of the error message in the returned value.

So all you need to do  {assuming you have already created a PDF file, $pdf is 
the filename and $fax_no is the number to send it to}  is something like

$fax_output = `sendfax -d $fax_no $pdf 2>&1`;

and then do a preg_match() to find any error messages.


I don't know where your PDFs are coming from; but if you're generating them 
on-the-fly, don't forget you can use html2ps to render an existing HTML file  
{or one you just created .....}  into PostScript -- sendfax also accepts this 
format.  The syntax would be something like

$fax_output = `html2ps $html_file | sendfax -d $fax_no - 2>&1`;

i.e.  you pipe the output of html2ps directly into sendfax, using - as a 
filename just means take input from STDIN.


There's one thing to beware of.  If you just make the `sendfax` unconditional, 
then refreshing the page in the browser will cause the fax to be re-sent!  
You probably do not want this behaviour, so you will have to keep track of 
what has been faxed recently from where.  You can do this by setting cookies 
or using session variables {which automatically ties the list of sent faxes 
to the browser instance},  or through a file or database on the server.  A 
database might actually be easier, since you can do a query like

SELECT COUNT(*) FROM webfaxdb WHERE ip='$ip` AND n='$fax_no' AND 
t>=$ten_mins_ago

where $ip = $_SERVER["REMOTE_ADDR"], t is a UNIX timestamp field  {you can 
fill it in from time()} and $ten_mins_ago = time() - 600

rather than having to parse a long text file.


Good luck with it and feel free to ask if you have any specific questions!

--
AJS

____________________ HylaFAX(tm) Users Mailing List _______________________
  To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi
 On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null
  *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*



Home
Report any problems to webmaster@hylafax.org

HylaFAX is a trademark of Silicon Graphics Corporation.
Internet connectivity for hylafax.org is provided by:
VirtuALL Private Host Services