Jump to content

PHP Listing Non Existent Error


JesseElser
Go to solution Solved by ginerjm,

Recommended Posts

I'm getting an error and no matter how many people look at the code no one can figure out why.

 

The error I'm getting is:

 

Parse error: syntax error, unexpected '$ratio_orig' (T_VARIABLE) in /home/jollyrogerpcs/public_html/img/gallery/thumbnail.php on line 23

 

The code is:

 

// thumb width

$square = 150;

$large = 200;

$small = 100;

////////////////////////////////////////////////////////////////////////////////// square

if( isset($_GET["img"]) &&  ( $_GET["type"] == "square" || $_GET["type"] == "" ) ){

// thumb size

$thumb_width = $square;

$thumb_height = $square;

// align

$align = $_GET["align"];

// image source

$imgSrc = $_GET["img"];

$imgExt = substr($imgSrc,-3);

// image extension

if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); }

if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); }

if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); }

// getting the image dimensions 

list($width_orig, $height_orig) = getimagesize($imgSrc);  

// ratio

$ratio_orig = $width_orig/$height_orig;

// landscape or portrait?

if ($thumb_width/$thumb_height > $ratio_orig) {

$new_height = $thumb_width/$ratio_orig;

$new_width = $thumb_width;

} else {

$new_width = $thumb_height*$ratio_orig;

$new_height = $thumb_height;

}

// middle

$x_mid = $new_width/2;

$y_mid = $new_height/2;

// create new image

$process = imagecreatetruecolor(round($new_width), round($new_height));

imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);

$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

// alignment

if($align == ""){

imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);

}

if($align == "top"){

imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), 0, $thumb_width, $thumb_height, $thumb_width, $thumb_height);

}

if($align == "bottom"){

imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($new_height-$thumb_height), $thumb_width, $thumb_height, $thumb_width, $thumb_height);

}

if($align == "left"){

imagecopyresampled($thumb, $process, 0, 0, 0, ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);

}

if($align == "right"){

imagecopyresampled($thumb, $process, 0, 0, ($new_width-$thumb_width), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);

}

imagedestroy($process);

imagedestroy($myImage);

if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); }

if($imgExt == "gif"){ imagegif($thumb); }

if($imgExt == "png"){ imagepng($thumb, null, 9); }

}

// normal

if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){

if( $_GET["type"] == "large" ){ $thumb_width = $large; }

if( $_GET["type"] == "small" ){ $thumb_width = $small; }

// image source

$imgSrc = $_GET["img"];

$imgExt = substr($imgSrc,-3);

// image extension

if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); }

if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); }

if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); }

//getting the image dimensions 

list($width_orig, $height_orig) = getimagesize($imgSrc);  

// ratio

$ratio_orig = $width_orig/$height_orig;

$thumb_height = $thumb_width/$ratio_orig;

// new dimensions

$new_width = $thumb_width;

$new_height = $thumb_height;

// middle

$x_mid = $new_width/2;

$y_mid = $new_height/2;

// create new image

$process = imagecreatetruecolor(round($new_width), round($new_height));

imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);

$thumb = imagecreatetruecolor($thumb_width, $thumb_height);

imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);

if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); }

if($imgExt == "gif"){ imagegif($thumb); }

if($imgExt == "png"){ imagepng($thumb, null, 9); }

}

 

Every line has the required semicolons. All brackets are properly closed. I have zero clue why that error even exists and I had this posted on another site and no one could figure it out.

 

If it helps the script is from http://1stwebmagazine.com/generate-thumbnail-on-the-fly-with-php

Link to comment
Share on other sites

the code as posted above doesn't produce that error.

 

it's likely that something about how it was published, with the highlighting, and how you copied it into your file or what you used as an editor got some encoded characters or the edits you did introduced a curly/smart-quote instead of a straight-quote.

 

i would copy/paste the above into a completely new file and try it.

Link to comment
Share on other sites

You have some extra hidden chars at the end of this line right before $ratio_orig is ref'ed

list($width_orig, $height_orig) = getimagesize($imgSrc);

Removed all of the extra characters that show as blank spaces. Error code is now changing lines which i assume is more special characters. Do you have any suggestions on how to easily find any of these special chars?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.