1. Exported my database to a .sql file, using phpmyadmin. Created a new database with the same name in WAMP and left it empty. Then imported it within the phpmyadmin environment using the import function from within the empty database. Initially got error message because the database exceeded the 2MB size limit (it was 7.5MB) but followed the directions as prompted to change the php.ini file so that the max_filesize parameter was 8MB.
2. PHP scripts that ran in MAMP initially wouldn't run in WAMP. Got error messages saying I had to initiallize array variables before using them, and "undefined constant blah, assumed 'blah' " meaning put array component names in quotes, as in $array["blah"] not $array[blah].
3. Various allowable permutations of embedding SQL commands within PHP using different orders of double or single quotes behave erratically in WAMP, much testing and debugging necessary.
4. Default user/password to access mysql in MAMP ("root"/"root") changed to "root"/"" in WAMP.
Monday, June 21, 2010
Sunday, March 21, 2010
Import PDF file into PHP script and superimpose text
The last post neglected to mention that the license to remove the PDF watermark costs over $500 (for PDFLib). I thought that since all the "native" php functions for php were activated the license would be free, or at least below $100. NOT.
So I switched to what turns out to be a three pronged solution using free libraries:
FPDF - from fpdf.org
FPDI - from setasign.de
FPDF_TPL - from setasign.de
Recipe:
1. FPDF Put fpdf.php into script folder. Put the font folder in there too.
2. FPDI Put entire contents of FPDI download (including fpdi.php) in the same folder.
3. FPDF_TPL Put fpdf_tlp.php into the same folder.
Now the sample scripts that come with FPDI and FPDF work!!
So I switched to what turns out to be a three pronged solution using free libraries:
FPDF - from fpdf.org
FPDI - from setasign.de
FPDF_TPL - from setasign.de
Recipe:
1. FPDF Put fpdf.php into script folder. Put the font folder in there too.
2. FPDI Put entire contents of FPDI download (including fpdi.php) in the same folder.
3. FPDF_TPL Put fpdf_tlp.php into the same folder.
Now the sample scripts that come with FPDI and FPDF work!!
Friday, March 19, 2010
Adding PDFlib to MAMP
(1) Download PDFLib 8.0
Don't install. Instead, enter the downloaded disk image, and surf to:
/bind/php/php-520/libpdf_php.so
Copy that file into:
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613
(2) Open Terminal and:
chmod +x /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/libpdf_php.so
(3) REM out
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
in the file
/Applications/MAMP/Library/bin/envvars
by adding # to the beginning of those two lines.
(4) Add
extension=libpdf_php.so
to extension section of php.ini for php5
REBOOT APACHE AND CHECK THAT PDFLIB IS ENABLED IN PHPINFO.
CREDITS TO JAMES WRIGHT IN THE MAMP FORUM. THANKS YOU JAMES WHERE EVER YOU ARE.
Don't install. Instead, enter the downloaded disk image, and surf to:
/bind/php/php-520/libpdf_php.so
Copy that file into:
/Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613
(2) Open Terminal and:
chmod +x /Applications/MAMP/bin/php5/lib/php/extensions/no-debug-non-zts-20060613/libpdf_php.so
(3) REM out
#DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#export DYLD_LIBRARY_PATH
in the file
/Applications/MAMP/Library/bin/envvars
by adding # to the beginning of those two lines.
(4) Add
extension=libpdf_php.so
to extension section of php.ini for php5
REBOOT APACHE AND CHECK THAT PDFLIB IS ENABLED IN PHPINFO.
CREDITS TO JAMES WRIGHT IN THE MAMP FORUM. THANKS YOU JAMES WHERE EVER YOU ARE.
Saturday, January 2, 2010
AppleScript and JavaScript
1. You can actually insert JavaScript commands inside AppleScript. The syntax is "do JavaScript", as in:
tell application "Safari" to do JavaScript "alert('Hello, world!')" in document 1
or
do JavaScript "window.print()" in document 1
2. You can write blocks of JavaScript code and then save the code as a bookmark, and then call the bookmark from a browser, and the JavaScript code will run. There is a lot on the web on this trick, which even has a name: Bookmarklet. There are all kinds of Bookmarklets out there for public consumption, like widgets. You can have an onscreen calculator, you can change the color scheme of a web page, you can fill out a web page, etc. etc.
3. You can pass variables from an AppleScript to a web server by inserting the variables into an HTML GET, as in:
set the URL of document 1 to "http://localhost:8888/foo.php?key1=" & val1 & "&key2=" & val2
4. You can use your iPhone as a dictaphone by using the free Dragan App (trick: "send to clipboard")
You can automatically send the clipboard contents to MobileMe email (trick: use free ClipMail app)
MobileMe email is push email, and can be used to launch an AppleScript on a MacBook Pro (trick: use Apple Mail Rules)
AppleScript can retrieve the contents of the email, parse it, and send it to a web server by calling a php script which inserts the contents into an SQL database.
Thus, following these steps, you can DICTATE into your phone and the text is instantly available in a REMOTE SQL SERVER, already parsed, with individual words and phrases sorted and inserted into records.
5. You can debug AppleScripts by having the script SPEAK the variable values or DISPLAY the variable values in dialog boxes:
display dialog var1
set speakString to "The value of var1 is" & var1
say speakString
tell application "Safari" to do JavaScript "alert('Hello, world!')" in document 1
or
do JavaScript "window.print()" in document 1
2. You can write blocks of JavaScript code and then save the code as a bookmark, and then call the bookmark from a browser, and the JavaScript code will run. There is a lot on the web on this trick, which even has a name: Bookmarklet. There are all kinds of Bookmarklets out there for public consumption, like widgets. You can have an onscreen calculator, you can change the color scheme of a web page, you can fill out a web page, etc. etc.
3. You can pass variables from an AppleScript to a web server by inserting the variables into an HTML GET, as in:
set the URL of document 1 to "http://localhost:8888/foo.php?key1=" & val1 & "&key2=" & val2
4. You can use your iPhone as a dictaphone by using the free Dragan App (trick: "send to clipboard")
You can automatically send the clipboard contents to MobileMe email (trick: use free ClipMail app)
MobileMe email is push email, and can be used to launch an AppleScript on a MacBook Pro (trick: use Apple Mail Rules)
AppleScript can retrieve the contents of the email, parse it, and send it to a web server by calling a php script which inserts the contents into an SQL database.
Thus, following these steps, you can DICTATE into your phone and the text is instantly available in a REMOTE SQL SERVER, already parsed, with individual words and phrases sorted and inserted into records.
5. You can debug AppleScripts by having the script SPEAK the variable values or DISPLAY the variable values in dialog boxes:
display dialog var1
set speakString to "The value of var1 is" & var1
say speakString
Saturday, November 28, 2009
Unzipping a file using PHP
The correct way is to use the unzip library but there are various problems with that approach that I won't harp on here. Another correct way is to use
exec("unzip /path/to/file.zip");
but I have found some zip files that the unix unzip command can't handle but that the mac os x built-in archive utility has no problem with. So I came up a simple, but goofy approach:
use php exec() to call an applescript which tells finder to open the file with archive utility, using a keyboard shortcut.
PHP blah.php
exec('osascript /applications/mamp/htdocs/zipfolder/asunzip.scpt');
APPLESCRIPT asunzip.scpt
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
key code 125 — down arrow
keystroke "z" using command down
end tell
end tell
KEYBOARD SHORTCUT - application-specific (system preferences)
command z is pulling file -> open with -> archive utility out of finder toolbar
———————————Addendum———————————————————
Here is a better AppleScript that does the same thing. But instead of bringing Finder to the forefront, then using down arrows to navigate to a file, and then using a keyboard shortcut to open it, it just directly opens the file by name quietly in the background:
set filepath to POSIX path of "Macintosh HD:Applications:MAMP:htdocs:zipfolder:neworig.zip"
application
try
set command to "open " & quoted form of filepath
do shell script command
end try
exec("unzip /path/to/file.zip");
but I have found some zip files that the unix unzip command can't handle but that the mac os x built-in archive utility has no problem with. So I came up a simple, but goofy approach:
use php exec() to call an applescript which tells finder to open the file with archive utility, using a keyboard shortcut.
PHP blah.php
exec('osascript /applications/mamp/htdocs/zipfolder/asunzip.scpt');
APPLESCRIPT asunzip.scpt
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
key code 125 — down arrow
keystroke "z" using command down
end tell
end tell
KEYBOARD SHORTCUT - application-specific (system preferences)
command z is pulling file -> open with -> archive utility out of finder toolbar
———————————Addendum———————————————————
Here is a better AppleScript that does the same thing. But instead of bringing Finder to the forefront, then using down arrows to navigate to a file, and then using a keyboard shortcut to open it, it just directly opens the file by name quietly in the background:
set filepath to POSIX path of "Macintosh HD:Applications:MAMP:htdocs:zipfolder:neworig.zip"
application
try
set command to "open " & quoted form of filepath
do shell script command
end try
Sunday, November 8, 2009
PHP mail() bug? or feature?
PHP mail bug
I use the php mail() function to create lengthy html emails. The $message is a long string, up to 5000 characters, or more, long. Well, it turns that either the mail() function or the mail server at the other end has a character limit of 990 per string. If you exceed that, something automatically inserts 0D 0A 20 into the string (CR LF Space) every 990 characters, so that now the email conforms to the "rule." No crash, but every 990 characters you see a space inserted in the middle of words, or if the space lands in a tag, you have screwed up your message format.
The fix: create a function that takes your $message string, and inserts 0D 0A 20 more frequently than every 990 characters where there normally is just a space (20). (20 is hex ascii for space - used a hex editor to debug this thing). If your message is html, html ignores CR LF in strings, so inserting this causes no problems. Then, after applying that function, use
mail( $to, $subject, $message, $headers );
on the modified $message, and it goes through without the problem!
Mac Shortcut of the Day
I really like the Safari "Bookmark Bar" across the top of the toolbar for quickly clicking to favorite sites. As if that wasn't good enough already, try holding the command key down while clicking a book mark. This gives you a new tab in your Safari window AND jumps you to your favorite site in one click.
I use the php mail() function to create lengthy html emails. The $message is a long string, up to 5000 characters, or more, long. Well, it turns that either the mail() function or the mail server at the other end has a character limit of 990 per string. If you exceed that, something automatically inserts 0D 0A 20 into the string (CR LF Space) every 990 characters, so that now the email conforms to the "rule." No crash, but every 990 characters you see a space inserted in the middle of words, or if the space lands in a tag, you have screwed up your message format.
The fix: create a function that takes your $message string, and inserts 0D 0A 20 more frequently than every 990 characters where there normally is just a space (20). (20 is hex ascii for space - used a hex editor to debug this thing). If your message is html, html ignores CR LF in strings, so inserting this causes no problems. Then, after applying that function, use
mail( $to, $subject, $message, $headers );
on the modified $message, and it goes through without the problem!
Mac Shortcut of the Day
I really like the Safari "Bookmark Bar" across the top of the toolbar for quickly clicking to favorite sites. As if that wasn't good enough already, try holding the command key down while clicking a book mark. This gives you a new tab in your Safari window AND jumps you to your favorite site in one click.
Saturday, November 7, 2009
I am a mac person now
I made the big switch about a month ago and I have never looked back. Virtually everything I used to do using computers I can do better now that I finally have a mac. I have Snow Leopard and haven't come up with any major problems yet. I am printing wirelessly three printers ( direct via bluetooth at home, direct via Wi-Fi (router attached to printer) at work, and via smb to another networked printer at work. The latter two were trickey: direct via Wi-Fi you have to find out the printer's IP address, and to find that out you have to hold down one of the printer's buttons to make it print it's identifying information, including the IP address. For the networked printer, even trickier. You have to find out the URL of the printer on the network and translate it into a format mac understands: in my case it is smb://xxx-03.yyy.phy/HPLaserJ. (That's the networked computer name/PrinterName) I needed to download Snow Leopard drivers for the first two printers; for the third, no driver needed since it is a shared printer.
Other fun things I have learned: Snow Leopard has a built-in VNC client, which means that with the free app VNC Lite I can see and control everything on the mac desktop over the Wi-Fi network on the screen of the iphone. in fact, I just typed this sentence using VNC on the iphone. It is useful if I want to dicate into MacSpeech Dictate using my wearable wireless microphone while in a different room from the Mac. I can still watch the words pop up on the iphone via VNC. Woo.
More great stuff: Mac Mail Rules and Applescript. You can define Rules for mail that act like powerful little macros and the rules can invoke Applescript scripts. Since mobile me email is "push", I can write php scripts on my MAMP server, and run the scripts remotely using the iphone, which results in pushing commands to the mac via mobile me -> via rules -> via applescript. In this manner I can print customized documents to a crisp laser printer right off of my iphone, and I can alter the content of document by entering the data on the phone via MAMP, and the php script handles the formatting (because it's html email with formatting tags). Two big helps on this: (1) Get rid of the unwanted headers (Mail->Preferences->Viewing->Show Header Details->None. (2) Rules run on the mac BEFORE the mail message that triggers the rule is delivered. So send a second mail message with the actual command in the subject line AFTER the HTML message is received (in php: sleep(1); makes the script wait just long enough to work) .
I'll mention a few more things in less detail: Finder -> Command-K is similar to Windows Key-R for connecting to servers: but instead of \\servername use smb://servername. When adding printers, remember to click the plus sign and then control-click the menu bar to get the option to customize the menu bar by adding the "Settings" icon. Built-in Automator macro app. Publishing your iCal calendar on-line for integration into your family's various calendars on their iCals (and iphones via mobile me). Time machine. Backup. The keyboard shortcuts under System Preferences -> Language and Text AND System Preferences -> Keyboard.
In short, it's a whole new world and a better one. Wow.
Other fun things I have learned: Snow Leopard has a built-in VNC client, which means that with the free app VNC Lite I can see and control everything on the mac desktop over the Wi-Fi network on the screen of the iphone. in fact, I just typed this sentence using VNC on the iphone. It is useful if I want to dicate into MacSpeech Dictate using my wearable wireless microphone while in a different room from the Mac. I can still watch the words pop up on the iphone via VNC. Woo.
More great stuff: Mac Mail Rules and Applescript. You can define Rules for mail that act like powerful little macros and the rules can invoke Applescript scripts. Since mobile me email is "push", I can write php scripts on my MAMP server, and run the scripts remotely using the iphone, which results in pushing commands to the mac via mobile me -> via rules -> via applescript. In this manner I can print customized documents to a crisp laser printer right off of my iphone, and I can alter the content of document by entering the data on the phone via MAMP, and the php script handles the formatting (because it's html email with formatting tags). Two big helps on this: (1) Get rid of the unwanted headers (Mail->Preferences->Viewing->Show Header Details->None. (2) Rules run on the mac BEFORE the mail message that triggers the rule is delivered. So send a second mail message with the actual command in the subject line AFTER the HTML message is received (in php: sleep(1); makes the script wait just long enough to work) .
I'll mention a few more things in less detail: Finder -> Command-K is similar to Windows Key-R for connecting to servers: but instead of \\servername use smb://servername. When adding printers, remember to click the plus sign and then control-click the menu bar to get the option to customize the menu bar by adding the "Settings" icon. Built-in Automator macro app. Publishing your iCal calendar on-line for integration into your family's various calendars on their iCals (and iphones via mobile me). Time machine. Backup. The keyboard shortcuts under System Preferences -> Language and Text AND System Preferences -> Keyboard.
In short, it's a whole new world and a better one. Wow.
Subscribe to:
Posts (Atom)