Don’t look at me I’m hideous – It’s about CakePHP Y’all

Written by James McDonald

March 22, 2011

How I got into this mess
This is what happens when you are learning.

Using the sample code from a CakePHP image upload tutorial

Beginner getting debug output from PHP Scripts
Couldn’t figure out how to get meio_upload.php and PHPThumbs debug output to go to screen or anywhere else for that matter (my screen went all white when I tried print_r from either meio_upload.php or phpthumb.class.php. But ended up using simple fopen to get info out. Something like this.

$myFile = "/tmp/testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $this->sourceFilename );

Then I could view the contents of variables.

Help: If anyone can tell me how those ubiquitous “$this->DebugMessage” PHPThumb statements can be viewed while using it in Object mode. I would be grateful.

Fixing PHPThumb Incorrectly Resolving the Image Path
The PHPThumb call was failing deep in the guts of the phpthumb.class.php file saying the image it was trying to convert “does not exist”. I have had to do some digging but discovered the problem:

The real physical path to where the image upload was saving was:

I access the cakephp sample application from a browser at http://localhost/jm/test/images. Apache is Aliasing /jm/ to /home/me/maps/www

The path that was being built by PHPThumb originally was:
Because it was pulling in Apaches system wide configured DOC_ROOT of /var/www and then tacking on /jm/test/

Then I edited phpThumb to change doc root to something real thusly:
$phpThumb->setParameter(‘config_document_root’, ‘/home/ja/maps/www/test’);

and got:
Getting closer but should be

Still wrong:
Finally went in to phpthumb.class.php into the ResolveFilenameToAbsolute and stopped PHPThumb referencing the PHP_SELF variable which was putting in the Aliased path and changed config_document_root to go as far as it needed which in my case was
$phpThumb->setParameter(‘config_document_root’, ‘/home/me/maps/www/test/app/webroot’);

and with the filename passed in of “img/uploads/images/filename.jpg”

Woohoo Touchdown we have the correct path for PHPThumb to generate a thumbnail

It finally worked. Not sure this is secure but it works.

function ResolveFilenameToAbsolute($filename) {

//... choppage. I mean I've trimmed a heap of code 
		} else {

			// relative to current directory (any OS)
// This doesn't work
 // $AbsoluteFilename = $this->config_document_root.dirname(@$_SERVER['PHP_SELF']).DIRECTORY_SEPARATOR.$filename;

// I configured config_document_root = /path/to/my/cakephp/install/
// the filename passed in so I just made sure it worked
$AbsoluteFilename = $this->config_document_root.DIRECTORY_SEPARATOR.$filename;
		// ... choppage 

Note to self: Bluefish is a good editor for PHP projects. I like the code completion for PHP functions.


Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…

Scam call from “Telstra”

Just had a call from a man with a sub-continental accent from caller ID 0734946596 Told me there was problem with my...

PC Build

I recently built myself a PC using the SilverStone SG13 Case. I am planning to use it as a Hot Spare. So any client...