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 );
fclose($fh);

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:
/home/me/maps/www/test/app/webroot/img/uploads/images

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:
/var/www/jm/test/img/uploads/images/filename.png
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:
/home/me/maps/www/test/jm/test/img/uploads/images/filename.jpg
Getting closer but should be
/home/me/maps/www/test/app/webroot/img/uploads/images

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
“/home/me/maps/www/test/app/webroot/img/uploads/images/filename.jpg”

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.

0 Comments

Submit a Comment

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

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...