Jump to content

Need extra eyes. Parse Error


Skipjackrick

Recommended Posts

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /public_html/addaprofile_photos_submit.php on line 16

 

I can't seem to find it.  Where's Waldo?

 

<?php  // addaprofile_photos_submit.php
  session_start();
  if( !isset($_SESSION['addId']) ) {
    // error - need session to be here
    header("Location: addaprofile_error.php");
    exit();
  } else {
    // session active
    //
    // define save image function
    function SaveImage( $id, $label ) {
      $filenameNew = getcwd() . '\avatars\' . $id . $label . '.jpg';
      if( is_file($filenameNew) ) {
        @unlink($filenameNew); 
      }
      $_SESSION['avatar_size'] = '0';
      $filename = $_FILES['prfFilename']['tmp_name'];
      if( $filename == '' ) {
        return 'No file uploaded';
      }
      switch( $_FILES['prfFilename']['type'] ) {
      case 'image/gif':
      case 'image/png':
      case 'image/jpeg':
      case 'image/pjpeg':
        // good image types
        break;
      default:
      return 'Unsupported image type: ' . $_FILES['prfFilename']['type'];
      }
      if ($_FILES['prfFilename']['error'] > 0) {
        // error trying to read file
        switch( $_FILES['prfFilename']['error'] ) {
        case 1:
          return 'File size exceeds limit of ' . ini_get(upload_max_filesize);
          break;
        case 2:
          return 'File size exceeds 1MB limit';
          break;
        case 3:
          return 'File was only partially loaded';
          break;
        case 4:
          return 'No file was uploaded';
          break;
        case 6:
          return 'Missing temporary folder';
          break;
        case 7:
          return 'File failed to write to disk';
          break;
        case 8:
          return 'File upload stopped by extension';
          break;
        default:
          return 'Unknown errorcode: ' . $_FILES['prfFilename']['error'];
      } }
      list($width, $height, $type) = getimagesize($filename);
      // Get new dimensions
      $widthMax  = 1024;
      $heightMax = 1024;
      if( $width > $widthMax ) {
        $widthNew = $widthMax;  // limit width to 1024
      } else {
        $widthNew = $width;
      }
      if( $height > $heightMax ) {
        $heightNew = $heightMax;  // limit height to 1024
      } else {
        $heightNew = $height;
      }
      if( $widthNew/$width < $heightNew/$height ) {
        $heightNew = floor($height*$widthNew/$width);  // use width ratio
      } else {
        $widthNew = floor($width*$heightNew/$height);  // use height ratio
      }
      // Scale image in memory
      $imageNew = imagecreatetruecolor($widthNew, $heightNew);
      if( !imageNew ) {
        return 'Memory error creating image';
      }
      switch( $type ) {
      case IMAGETYPE_JPEG:
        $image = imagecreatefromjpeg($filename);
        break;
      case IMAGETYPE_GIF:
        $image = imagecreatefromgif($filename);
        break;
      case IMAGETYPE_BMP:
        $image = imagecreatefrompng($filename);
        break;
      default:
        return 'Invalid image format:' . $type;
      }
      if( !$image ) {
        return 'Error reading image' . $type;
      }
      if( !imagecopyresampled($imageNew, $image, 0, 0, 0, 0,
        $widthNew, $heightNew, $width, $height) ) {
        return 'Error copying and scaling image';
      }
      // Output to upload location, 75 is quality scale 1 - 100
      if( !imagejpeg($imageNew, $filenameNew, 75) ) {
        return 'Error storing image';
      }
      imagedestroy($image);
      imagedestroy($imageNew);
      $_SESSION['avatar_size'] = strval(filesize($filenameNew));
      return 'Upload Successful';
    }
    //
    // process photos
    $anglerId = $_SESSION['anglerId'];		 // get current angler profile id
    $prfLabel = $_POST['prfLabel'];		 // get picture label ex. avatar
    $_SESSION['errorUpload'] = '';		// clear error message
    $results = '';
    $results = SaveImage( $anglerId, $prfLabel );
    if( $results != 'Upload Successful' ) {
      // upload error
      $_SESSION['errorUpload'] = $prfLabel .': ' . $results;
    } else {
      // no error, let's go prep data for db
      $_SESSION['signature'] = stripslashes($_POST['signature']);
      include 'db_connect.php';	// include database connection

        $prfCaption = mysql_real_escape_string($_SESSION['signature']);	
        $sql = "UPDATE anglers SET 
                  avatar_size = {$_SESSION['avatar_size']},
                  signature = '$prfCaption'
               ";
  
      $sql .= "WHERE anglerId = $anglerId";
      $result = mysql_query($sql) or die(mysql_error());
    }
    //
    header('Location: addaprofile_photos.php');
    exit();
  }
?>

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.