I am having trouble with some php code that was working fine on a unix server but when I try to move it to a Windows 2003 server I am getting errors like "Use of undefined constant x - assumed 'x' in ...".

I am using PHP 5. Here is the code that deals with defining x:

$x = escapeshellarg( $_GET[x] );

What should I do? thanks.

What version of php are you using 5.2 or earlier? I think some versions of pHp have an issue with not escaping double quote marks properly. Have you tried using different values for the variable from shell?

Thanks for the quick reply. I am using php 5.2.6

As to your other question, this is probably not what you want to hear but I am a neophyte at php programming. I don't know very much. I am using some code obtained from someone else so I did not write it.

I am getting errors about undefined constants x, y, rotate and scale. I was getting errors about

Here is some more of the code.

CheckParameters();

$alltext = @file_get_contents( fixurl( stripslashes($_GET['url']) ) );
if ( $alltext === false ) {
	$cache->remove( $_SERVER['REQUEST_URI'] );
	die();
}

$tempfile1 = tempnam( "/tmp", "resize-foo-ok-to-delete-" );
file_put_contents( $tempfile1, $alltext );

$x = escapeshellarg( $_GET[x] );
$y = escapeshellarg( $_GET[y] );
$mogrify = "mogrify";

if ( $_GET[rotate] ) {
	$rotate = "-rotate {$_GET[rotate]}\>";
}

if ( $_GET[scale] ) {
	$rc = system( "nice $mogrify -size {$_GET[scale]}% -resize {$x}x{$y} $rotate $tempfile1" );
} else {
#$rc = system( "nice $mogrify -size {$x}x{$y} -resize {$x}x{$y} +profile \"*\" $tempfile1" );
	$rc = system( "nice $mogrify -size {$x}x{$y} -resize '{$x}x{$y}>' $rotate $tempfile1" );
}

I am getting errors about undefined constants x, y, rotate and scale.

I was getting errors about the unix command REQUEST_URI till I followed the directions at http://neosmart.net/blog/2006/100-apache-compliant-request_uri-for-iis-and-windows/

I was thinking the undefinded variable error was also something related to transferring the code from Unix to Windows but I really don't know. To directly answer your last question - no I have not tried using different values for the variable from shell. I don't know how to do that. Sorry. Perhaps the expanded code I posted will give you another clue for me to try.

I'm no expert on UNIX vs. Windows servers, but it might be that UNIX is more forgiving that Windows as buddylee17 suggests single quoting your $_GET parameters:

So change to:

$x = escapeshellarg( $_GET['x'] );
$y = escapeshellarg( $_GET['y'] );
$mogrify = "mogrify";

if ( $_GET['rotate'] ) {
	$rotate = "-rotate {$_GET['rotate']}\>";
}

if ( $_GET['scale'] ) {
	$rc = system( "nice $mogrify -size {$_GET['scale']}% -resize {$x}x{$y} $rotate $tempfile1" );
} else {
#$rc = system( "nice $mogrify -size {$x}x{$y} -resize {$x}x{$y} +profile \"*\" $tempfile1" );
	$rc = system( "nice $mogrify -size {$x}x{$y} -resize '{$x}x{$y}>' $rotate $tempfile1" );
}

However, I've very little experience with shell arguments. Further quoting may help???! Perhaps replacing " with '.

Thanks Buddylee. Adding the single quotes to the x and y variable fixed those error messages. However I'm still getting error messages on the rotate and scale variables. With or without the quotes, I get:
Undefined index: rotate

Is rotate in the querystring (the part of the url after the ?)?

Your querystring should be something like:
http://www.yoursite.com/page.php?x=1&y=2&rotate=left&scale=50

You are then pulling them out of the string and assigning them to a variable with $_GET. If the value is not in the querystring, you'll get an undefined index.

rotate is likely to be a angle value, somewhere in range 0f either
-180 to +180
or
-pi to +pi
depending on world geometry polar or cartesian

Thanks all for your helpful suggestions. Clearly I'm in over my head and so I will go back to a simpler script using the php command imagecopyresized.

Thanks again for responding to my questions.

Regards,
-Larry

This article has been dead for over six months. Start a new discussion instead.