Friday, December 31, 2010

PHP Script to send PDF file as attachment (requires FPDF object)

function mail_pdf_as_attachment($pdfobj,$faxnumber) {
$pdfdoc = $pdfobj->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
$to = "destinationaddress@destination.com";
$from = "sourceaddress@source.com";
$subject = $faxnumber;
$message = "See attached pdf file";
$separator = md5(time());
$eol = PHP_EOL;
$filename = "medfax6.pdf";
//headers
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$headers .= $message.$eol.$eol;
// attachment
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$headers .= "Content-Transfer-Encoding: base64".$eol;
$headers .= "Content-Disposition: attachment".$eol.$eol;
$headers .= $attachment.$eol.$eol;
$headers .= "--".$separator."--";
mail($to, $subject, "", $headers);
}

Dual Formatting of External Hard Drives (PC and MAC)

You can do that?? It turns out, yes.

Plug the drive into a USB port on the mac. Go into Disk Utility (You can find the utility fastest by clicking on the "magnifying glass" shaped icon on the far upper right corner of the screen, which is called Spotlight, and typing Disk Utility.

Then partition the drive, selecting the option to create 2 partitions. This will format the external drive. Select mac formatting for one and MS-DOS FAT for the other. The trick is go go into "Options" after you enter the Partitions tabs and under options select the bottom of the three options, which allows you to create a root directory that will allow the MS-DOS partition. Otherwise, it isn't even an option.

After being done formatting, you will see both partitions on the mac with their assigned names, and if you plug into a PC you will only see the PC partition with its name and letter, like E: as assigned by the PC.

Hosting Content on the World Wide Web on a Laptop

I have a Macbook Pro (MBP) running Snow Leopard. It is connected to the internet through a wireless router. I am running MAMP on it and using it as a server, and I access the server from the iPhone, or the iPad, from WITHIN the LAN (behind the router) via the Wi-Fi connection to that router. Wouldn't it be nice to be able access that same server remotely, from OUTSIDE the LAN, via, say, a 3G connection?

Three steps to doing this:
1. Find out what the IP address is (whatismyip.com)
2. Tell the ROUTER to assign a static IP address to the MBP within the LAN
login to router as admin ->LAN setup->Use Router as DHCP Server->Address Reservation
In my case, I just selected the address it had randomly assigned to make it permanent (192.168.1.18)
You need to know your computer's name and/or mac address to do this, so that you select the correct computer.
3. Then you need to go to port forwarding (still in admin in the ROUTER settings), and assign start port 8888 to forward to end port 8888 on 192.168.1.18.

Finally, step outside the LAN and browse to:
ipaddress:8888/homefolder/index.php
and you are there.

CAUTION: if you do this and leave your server on, your precious MBP is on the world wide web, and can be subject to cyber attack. It helps that the port is not 80, or 8080, which are far more common, but still, take precautions.