Archive for the ‘Php’ Category.

Easily Email Images With Microsoft Outlook

5-21-2009-10-53-00-amHere is a small utility to more easily email photos with Microsoft Outlook. Basically, it allows you to embed images in the body of the email message so that it is easier for the recipient to view the files.

5-20-2009-2-42-02-pmDownload the file using the link below. Once downloaded, install it by double-clicking it. To use the program, simply highlight the photos you wish to send, then right-click one of the highlighted images and select "Send-To" then "Image Mailer for Outlook". Image Mailer will resize the images to an appropriate size for e-mailing if necessary and then automatically create the e-mail for you with the images embedded in the body of the message. (Click the small image to the right for a better idea...)

5-27-2009-11-48-18-am

If you wish to change settings, like how large the image is when it's in the body of the message, you can use the settings editor included. Simply click on Start, All Programs, Deciacco.com, Image Mailer, and finally Settings.

There are three basic settings to choose from. The best settings for most people will be selected by default, but you may choose something to better fit your needs. Try experimenting with the different settings to see what suits you best.

Please note that while we have made are best efforts to insure its function you use this program at your own risk. In other words, you can use this program, but we don't want to get sued.

Please check back here for version updates and if you find a bug or would like an enhancement, feel free to leave a comment on this post or contact me directly via the e-mail on my contact page.

Click here to download the Windows 98 and up installer (2.1Mb)

WP-DBManager Backup DB Fix For Windows

For this blog I like to use a plugin called WP-DBManager. It's a great tool for easily maintaining your blog's database right from the administration console. Unfortunately, being on a Windows host, sometimes plugins don't work as intended, so you have to make some adjustments.

For this plugin I kept getting this error whenever I tried to run the backup script:

Warning: filesize(): Stat failed for (blah, blah)
Warning: unlink(blah, blah) no such file or directory

To fix it I had to do a few things:

1. The actual command to create the backup needs to be fixed, so it can run properly on the command prompt. Find the file named database-backup.php in the plugin's directory. Place double quotes around the path part of the command and remove all others. Lines 47 and 51.

$backup['command'] = '"' . $backup['mysqldumppath'].'" --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table --skip-lock-tables '.DB_NAME.' | gzip > '.$backup['filepath'];

$backup['command'] = '"' . $backup['mysqldumppath'] . '" --host='.DB_HOST.' --user='.DB_USER.' --password='.DB_PASSWORD.' --add-drop-table --skip-lock-tables '.DB_NAME.' > '.$backup['filepath'];

2. The function that runs the command is called execute_packup(). This function is located in a file named wp-dbmanager.php in the plugin's directory. Find this function (line 205) and remove the if statement and leave only the passthru() command. Similar to this:

function execute_backup($command) {
	$backup_options = get_option('dbmanager_options');
	check_backup_files();
	/*if(substr(PHP_OS, 0, 3) == 'WIN') {
		$writable_dir = $backup_options['path'];
		$tmpnam = $writable_dir.'/wp-dbmanager.bat';
		$fp = fopen($tmpnam, 'w');
		fwrite($fp, $command);
		fclose($fp);
		system($tmpnam.' > NUL', $error);
		unlink($tmpnam);
	} else {*/
		passthru($command, $error);
	//}
	return $error;
}

3. If you want to have the gzip functionality you will need to download and place gzip.exe in the system32 folder of the server. You can download gzip from here.

NOTES:

  • Make sure the the Internet Guest Account has write permissions to the backup-db directory.
  • There is probably a better way to do this, perhaps using the exec() command in the if statement, but this one seems to work just fine.
  • Not necessary - On my server I had to put @ symbols in front of the filesize() and unlink() functions in the database-backup.php file, so that the they would not throw the php warning message and continue through to show the actual error message on the plugin page.

Image Resizer – Php Application for Windows (Almost)

I decided to write a small utility to quickly and easily resize images.

3-3-2009-10-19-53-pm

I wrote in PHP, and while PHP is mostly a "Web" language, it actually worked out quite nicely. You simply right-click an image or a folder containing images and select the appropriate command. Currently, the program supports JPEG, GIF, and PNG images. The original image remains intact as a new, resized version is created.

Installing

You can simply download the installer and run it on your computer. After the install, you will have an Image Resizer folder in your Start Menu as well as some new context menu(right-click) entries.

Launching

To start the program simply right-click on an image file and select "Resize Image". If you want to resize multiple files, right-click on the folder containing the images and select "Run Image Resizer On".

Program Settings

When you launch Image Resizer, it needs some information from you. You can specify this information in one of two ways. First, you can run it in interactive mode, where it will require you to input the settings every time. This is good when you require different image sizes often. Second, you can run Image Resizer in silent mode where you predefine the settings in the settings file. (The settings file is located in the program directory and shortcut to it is created in the program group in the Start Menu.) This is especially useful if you use Image Resizer to resize images before you send them in an email. Below are the required entries:

  1. Target Size
    • The maximum height or width in pixels the re-sized image can be. The aspect ratio will not change, therefore whichever side of the image is the longest will need to be the side to fit within the target size.
  2. Resized Image Postfix
    • Something to append to the end of the re-sized file's name.
    • Example: By taking the default value of "_resized", the image "silvesterkitty.jpg"
      will be copied and resized to "silvesterkitty_resized.jpg".
  3. Quality
    • The quality of the resized image. The higher the quality means the less atifacting will occure on the image and the final result is a more crisp looking image at the cost of higher file size.

*Note: To run image resizer in Silent mode, open the settings file and set "Silent" equal to 1.

**Note: Image Resizer always reads the values from the settings file, whether in interactive or silent mode. If in interactive mode, the values from the settings are used as the defaults.

Uninstalling

To uninstall, use the Windows uninstall utility from the control panel. All files, shortcuts,  and registry entries are removed.

Revision History

  • 0.1.3 - 03/03/2009
    • added the ability to run on a single file or by selecting multiple files
    • removed the ability to drag and drop; not needed as right-click is sufficient
    • removed the launch icon from the start menu
    • renamed the ini file shortcut in the program group to make more sense
    • added documentation to the settings file
    • fixed bug in installer when installing on Vista 32bit that caused the wrong registry entry to be installed which in turn caused the program to not lauch from the context menu
  • 0.1.2 - 02/16/2009
    • added installer
    • changed the resizing algorithm
    • no longer uses width and height, but uses a target size
  • 0.1.1 - 04/03/2008
    • cleaned up the registry entry to launch the php file itself instead of cmd.exe
    • the "Run Image Resizer On" context menu extension does not show when right-clicking the Recycle Bin

Download

Download Installer for XP, Vista here (3MB)

You can find more information on PHP at http://www.php.net/
Find some cool icons at the Icon Drawer - http://www.icondrawer.com/free.php
Special thanks to BojanM for contributing to this utility.

PHP, OpenSSL and ftp_ssl_connect() on Win32

For quite some time I've been wanting to compile PHP for the sole purpose of using the ftp_ssl_connect() function. According to the PHP manual:

ftp_ssl_connect() is only available if OpenSSL support is enabled into your version of PHP. If it's undefined and you've compiled FTP support then this is why. For Windows you must compile your own PHP binaries to support this function.

When I first saw this I was disappointed. I thought I would never be able to compile PHP myself. It just felt like a daunting task to get my system configured correctly.

Well, it's not perfect, but I have been able to get it to work, and I've even been able to patch up the PHP code itself!

Continue reading ‘PHP, OpenSSL and ftp_ssl_connect() on Win32’ »

Monitor Folder Service With PHP (Almost)

At the office we use a RICOH Aficio 1045 Copier. One of the features of this copier is that it also doubles as a scanner. To scan a document an employee goes to the copier, puts the copier in scanner mode, selects their mailbox from a list and then scans the document. The scanner then sends the scanned information to the scanner software running on one of our servers where the actual file is created and placed in the user's virtual mailbox. (We use pdf as the default.) Each user's virtual mailbox has a folder associated with it, and this folder is located in each user's personal folder on the server. Most of our employees have workstations and their "My Documents" folder is mapped to their personal folder on the server. By the time they get back to their desk, all they have to do is go into their "My Documents" folder and the scanned document is already there.

The problem is with notebook users who don't have a mapped "My Documents". If it were mapped, they would not be able to take their documents with them whenever they left the office. So, how can notebook users also retrieve their scanned documents from their "My Documents" folder?

Basically, all that is needed is some kind of mechanism to monitor a user's virtual mailbox, and when a new file is placed there, copy it down to the user's "My Documents" folder on the notebook.

PHP Solution:

Install PHP on your server/workstation that will be used to run this. (Google "PHP Install" for more info...)

Php doesn't have a built in way of creating Windows services, hence the "almost" in the title. So you can use two nice utilities called INSTSRV.EXE and SRVANY.EXE that come with the Windows Resource Kit. You can download it from here: Windows 2003 Resource Kit Tools

Once you've installed the kit you can use something similar to the following to install the service.

C:\Program Files\Windows Resource Kits\Tools>instsrv scansmon "d:\Program Files\Windows Resource Kits\Tools\srvany.exe"

SRVANY does all the work and Windows sees it as the service. SRVANY will look in the registry for the EXE file to use for the service. The EXE name, the starting directory, and any optional parameters should be in the registry as follows:


[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\
Services\scansmon\Parameters]
"AppDirectory"="D:\\Scripts\\Scansmon"
"Application"="php -q D:\\Scripts\\Scansmon\\scansmon.php3"
"AppParameters"=""

NOTE: You can copy/paste the lines above to a file named scansmon.reg (change the paths as necessary and make sure to include the double back-slashes) and double click the .reg file to add these entries to the registry.

Php itself is the EXE that it runs.

scansmon.php3 has the following code in it. (you will need to modify it for your network)

set_time_limit(0);

$user_a_user_directory = '\\\\Server01\\user\\user_a\\ScansIn\\';
$user_a_notebook_scans_directory = '\\\\user_a_notebook\\c$\\Documents and Settings\\user_a\\My Documents\\Scans\\';

$user_b_user_directory = '\\\\Server01\\user\\user_b\\ScansIn\\';
$user_b_notebook_scans_directory = '\\\\user_b_notebook\\c$\\Documents and Settings\\user_a\\My Documents\\Scans\\';

$loop = true;

while($loop){ //Will run as a windows service so loop infinitely
	$log_file = date("Ymd").".txt";

	writetolog("****************", $log_file);
	try{
		if (file_exists($user_a_user_directory) && file_exists($user_a_notebook_scans_directory)){
			writetolog("Ready to proceed with user_a scans...", $log_file);

			$oldfile = "";
			$newfile = "";

			if ($dir = opendir($user_a_user_directory)){
				while ($file = readdir($dir)){ //As long as there are files copy them and write to log
					$oldfile = $user_a_user_directory.$file;
					if (is_file($oldfile)){ //&& substr($file, -4) == '.pdf'
						$newfile = $user_a_notebook_scans_directory.$file;
						writetolog("copying $file", $log_file);
						if (!copy($oldfile, $newfile)){
							writetolog("failed to copy $oldfile...", $log_file);
						}else{
							unlink($oldfile);
							writetolog("deleted $oldfile...", $log_file);
						}
					}
				}
				closedir($dir);
			}
		}else{
			writetolog("Can't do user_a scans...", $log_file);
		}

		if (file_exists($user_b_user_directory) && file_exists($user_b_notebook_scans_directory)){
			writetolog("Ready to proceed we user_b scans...", $log_file);

			$oldfile = "";
			$newfile = "";

			if ($dir = opendir($user_b_user_directory)){
				while ($file = readdir($dir)){
					$oldfile = $user_b_user_directory.$file;
					if (is_file($oldfile)){ //&& substr($file, -4) == '.pdf'
						$newfile = $user_b_notebook_scans_directory.$file;
						writetolog("copying $file", $log_file);
						if (!copy($oldfile, $newfile)){
							writetolog("failed to copy $oldfile...", $log_file);
						}else{
							unlink($oldfile);
							writetolog("deleted $oldfile...", $log_file);
						}
					}
				}
				closedir($dir);
			}
		}else{
			writetolog("Can't do user_b scans...", $log_file);
		}

		writetolog("Waiting for 180 seconds...", $log_file);
		Sleep(180); //Wait three minutes before next check
	}
	catch(Exception $e){
		$loop = false;
		writetolog($e->getMessage(), $log_file);
	}
}

function writetolog($text, $file)
{
	$log_directory = 'D:\\Logs\\Scripts\\';
	$log_file = $log_directory.$file;
	$fh = fopen($log_file, 'a');
	fwrite($fh, date("h:i:s A")."  $text".chr(13).chr(10));
	fclose($fh);
}