Posts tagged ‘Php’

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’ »