Jump to content

Re: php4 to php5 conversion: Cannot re-assign $this


Yasoymama

Recommended Posts

I have the same problem, but I can't make it work!

I have little knowledge about PHP, so any help would be great for me...

This is my image.class.php:

 

class imageobject{

         var $handle;
         var $type="png";
         var $height=0;
         var $width=0;
         var $string;// for img height/width tags
         var $square;
         // output message
         var $message;
         // previous file
         var $previous;
         // current
         var $directory;
         var $filename;
         //output
         var $resample = false;
         var $quality="80";
         var $output=OUTPUT;// alternatives are png8 or png
         var $transparent; // only if output=png8
         // textobject
         var $previewobject;
         // option
         var $savefile = true;
         //
         var $newobj;

         //constructor
         function imageobject($directory,$filename,$width=0,$height=0,$color="FFFFFF")
                  {
                  $this->directory = $directory;
                  $this->filename = $filename;

                  if ($filename=="" && $width>0 && $height>0){

                     $new = $this->createImage($width,$height);
                     $col = ImageColorAllocate($new, hexdec(substr($color,0,2)), hexdec(substr($color,2,2)),hexdec(substr($color,4,2)));
                     ImageFilledRectangle($new,0,0,$width,$height,$col);
                     $this->newobj = $this->createUnique($new);
                     }elseif (file_exists($directory.$filename)){
                       $this->filesize = ceil(filesize($directory.$filename)/1024);
                       $size = GetImageSize($directory.$filename);
                       if ($size) $this->handle = $this->getHandle($directory.$filename,$size[2]);
                       $this->width = $size[0];
                       $this->height = $size[1];
                       $this->string = $size[3];
                       $this->square = $size[0]*$size[1];

                       if ($this->handle)
                         $this->message = $GLOBALS["message_supported"];
                       else
                         $this->message = $GLOBALS["message_not_supported"];
                       }
                  }// constructor

         // private methods
        function getHandle($name,&$type)
        {
           switch ($type){
              case 1:
              $im = imagecreatefromgif($name);
              $this->type= "gif";
              break;
              case 2:
              $im = imagecreatefromjpeg($name);
              break;
              case 3:
              $im = imagecreatefrompng($name);
              $this->type= "png";
              break;
                      }
           return $im;
        }

        function saveAlpha(&$handle)
        {
         ImageAlphaBlending($handle, true);
         imagesavealpha($handle,false);
         imagesavealpha($handle,true);
        }

        function getHexColor($xpos,$ypos)
        {
              $color = imagecolorat($this->handle, $xpos, $ypos);
              $colorrgb = imagecolorsforindex($this->handle,$color);

              if ($colorrgb["red"]>0)$hred = dechex($colorrgb["red"]); else $hred = "00";
              if (strlen($hred)<2)$hred = "0".$hred;

              if ($colorrgb["green"]>0)$hgreen = dechex($colorrgb["green"]); else $hgreen = "00";
              if (strlen($hgreen)<2)$hgreen = "0".$hgreen;

              if ($colorrgb["blue"]>0)$hblue = dechex($colorrgb["blue"]); else $hblue = "00";
              if (strlen($hblue)<2)$hblue = "0".$hblue;

              return strtoupper($hred.$hgreen.$hblue);
        }

        function uniqueName()
        {
          $add="";
          $fileparts = split("\.",$this->filename);
          $nonchr = array("__","0","1","2","3","4","5","6","7","8","9");
          $desc = str_replace($nonchr,"",$fileparts[0]);
          $name = $desc."__".date("YmdHms");
          // if exists add incremented number
          if (file_exists($this->directory.$name.".".$this->type)){
            $add = 1;
            while(file_exists($this->directory.$name.$add.".".$this->type)) $add++;
            }
          return $imgnew.$name.$add.".".$this->type;
        }

        function createUnique($imgnew)
        {
           $this->type = substr($this->output,0,3);

           $unique_str = $this->uniqueName();
           switch ($this->type){
              case "png":
                  imagepng($imgnew,RES_DIR.$unique_str);
              break;
              default:
                  imagejpeg($imgnew,RES_DIR.$unique_str,$this->quality);
              break;
              }

           $this->handle && imagedestroy($this->handle);
           $newobject = new imageobject(RES_DIR,$unique_str,$this->type);
           return $newobject;
        }

        function createImage($new_w,$new_h)
        {
           if (function_exists("imagecreatetruecolor") && $this->output!="png8"){
             return imagecreatetruecolor($new_w,$new_h);
             }else{
                return imagecreate($new_w,$new_h);
                }
        }

        function copyhandle(&$dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
        {

         if ($this->output=="png8" && $this->type="jpg"){
            imagecopyresized($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
            $this->resample==true;
            }

         if (function_exists("imagecopyresampled") && $this->resample==true)
            imagecopyresampled($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
         else
            imagecopy($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);

        }

        function copycreatehandle(&$src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
        {

          $dst_im = $this->createImage($dst_w,$dst_h);

          $this->copyhandle($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

          return $dst_im;
        }


         // public methods
        function resizeImage($scale,$newwidth=0,$newheight=0)
        {
           $new_w = $this->width;
           $new_h = $this->height;
           $aspect_ratio = (int) $new_h / $new_w;
           if ($scale) $new_w = $new_w * $scale;
           if ($newwidth>0) $new_w = $newwidth;
           if ($newheight>0){
                $new_h = $newheight;
                $new_w = (int) $new_h / $aspect_ratio;
                }else{
                   $new_h = abs($new_w * $aspect_ratio);
                   }
           $dst_img = $this->copycreatehandle($this->handle, 0, 0, 0, 0, $new_w, $new_h, $this->width,$this->height);

           return $this->createUnique($dst_img);
        }


        function cropImage($top,$right,$bottom,$left)
        {
           $new_w = $right - $left;
           $new_h = $bottom - $top;

           $dst_img = $this->copycreatehandle($this->handle, 0, 0, $left, $top, $new_w, $new_h, $new_w, $new_h);
           return $this->createUnique($dst_img);
        }


        function writeText($label, $xpos=0, $ypos=0, $textstring, $fontsize, $truetype, $fontcolor="FFFFFF",$fontangle)
        {
              $fontbgcolor= $this->getHexColor($xpos,$ypos);
              $textimage = new imagetext($truetype,$fontsize,$fontcolor,$textstring,$fontbgcolor,$fontangle);
              ImageAlphaBlending($this->handle, true);
              imagesavealpha($this->handle,false);
              imagesavealpha($this->handle,true);
              $this->copyhandle($this->handle, $textimage->handle, $xpos, $ypos, 0, 0, $textimage->dx, $textimage->dy,$textimage->dx, $textimage->dy);

              return $this->createUnique($this->handle);
        }

        function mergeImage($dir,$placedfile,$mergewidth,$mergeheight,$offx,$offy,$transcolor="")
        {
              $source = new imageobject($dir,$placedfile);
              $source->saveAlpha($source->handle);

              if ($transcolor){
                $r = hexdec(substr($transcolor, 0, 2));
                $g = hexdec(substr($transcolor, 2, 2));
                $b = hexdec(substr($transcolor, 4, 2));
                $color = imagecolorallocate($source->handle, $r, $g, $b);
                imagecolortransparent($source->handle,$color);
                }

              $this->saveAlpha($this->handle);
              ImageCopyResized($this->handle, $source->handle,$offx,$offy,0,0,$mergewidth,$mergeheight,$source->width,$source->height);

              return $this->createUnique($this->handle);
        }



   }// class

 

I tried to change $this with $thisio, as AbraCadaver said, but I am not able to make the script run.

Any help?

 

 

Link to comment
Share on other sites

First of all I recommend reading up on OOP in PHP 5, as what you have there is a PHP 4 style class.

 

I've taken the liberty of cleaning up the PHP 4 syntax sugar for you, and translating it into PHP 5 style.

<?php

class imageobject {
private $handle;
private $type = "png";
private $height = 0;
private $width = 0;
private $string; // for img height/width tags
private $square;
private $filesize; // CF: Was missing.

// output message
public $message;

// previous file
// var $previous; // CF: Commented out as it was not used.

// current
private $directory;
private $filename;

//output
private $resample = false;
private $quality = "80";
private $output = OUTPUT; // alternatives are png8 or png
private $transparent; // only if output=png8

// textobject
// var $previewobject; // CF: Commented out as it was not used.

// option
// var $savefile = true; // CF: Commented out as it was not used.

//
private $newobj;

//constructor
public function __construct ($directory, $filename, $width = 0, $height = 0, $color = "FFFFFF") {
	$this->directory = $directory;
	$this->filename = $filename;

	if ($filename == "" && $width > 0 && $height > 0) {
		$new = $this->createImage ($width, $height);
		$col = ImageColorAllocate ($new, hexdec (substr ($color, 0, 2)), hexdec (substr ($color, 2, 2)), hexdec (substr ($color, 4, 2)));
		ImageFilledRectangle ($new, 0, 0, $width, $height, $col);
		$this->newobj = $this->createUnique ($new);
	} elseif (file_exists ($directory . $filename)) {
		$this->filesize = ceil (filesize ($directory . $filename) / 1024);
		$size = GetImageSize ($directory . $filename);
		if ($size)
			$this->handle = $this->getHandle ($directory . $filename, $size[2]);
		$this->width = $size[0];
		$this->height = $size[1];
		$this->string = $size[3];
		$this->square = $size[0] * $size[1];

		if ($this->handle)
			$this->message = $GLOBALS["message_supported"];
		else
			$this->message = $GLOBALS["message_not_supported"];
	}
} // constructor


// private methods
private function getHandle ($name, &$type) {
	switch ($type) {
		case 1:
			$im = imagecreatefromgif ($name);
			$this->type = "gif";
			break;
		case 2:
			$im = imagecreatefromjpeg ($name);
			break;
		case 3:
			$im = imagecreatefrompng ($name);
			$this->type = "png";
			break;
	}
	return $im;
}

private function saveAlpha (&$handle) {
	ImageAlphaBlending ($handle, true);
	imagesavealpha ($handle, false);
	imagesavealpha ($handle, true);
}

private function getHexColor ($xpos, $ypos) {
	$color = imagecolorat ($this->handle, $xpos, $ypos);
	$colorrgb = imagecolorsforindex ($this->handle, $color);

	if ($colorrgb["red"] > 0)
		$hred = dechex ($colorrgb["red"]);
	else
		$hred = "00";
	if (strlen ($hred) < 2)
		$hred = "0" . $hred;

	if ($colorrgb["green"] > 0)
		$hgreen = dechex ($colorrgb["green"]);
	else
		$hgreen = "00";
	if (strlen ($hgreen) < 2)
		$hgreen = "0" . $hgreen;

	if ($colorrgb["blue"] > 0)
		$hblue = dechex ($colorrgb["blue"]);
	else
		$hblue = "00";
	if (strlen ($hblue) < 2)
		$hblue = "0" . $hblue;

	return strtoupper ($hred . $hgreen . $hblue);
}

private function uniqueName () {
	$add = "";
	$fileparts = split ("\.", $this->filename);
	$nonchr = array ("__", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
	$desc = str_replace ($nonchr, "", $fileparts[0]);
	$name = $desc . "__" . date ("YmdHms");

	// if exists add incremented number
	if (file_exists ($this->directory . $name . "." . $this->type)) {
		$add = 1;
		while (file_exists ($this->directory . $name . $add . "." . $this->type))
			$add++;
	}
	return $imgnew . $name . $add . "." . $this->type;
}

private function createUnique ($imgnew) {
	$this->type = substr ($this->output, 0, 3);

	$unique_str = $this->uniqueName ();
	switch ($this->type) {
		case "png":
			imagepng ($imgnew, RES_DIR . $unique_str);
			break;
		default:
			imagejpeg ($imgnew, RES_DIR . $unique_str, $this->quality);
			break;
	}

	$this->handle && imagedestroy ($this->handle);
	$newobject = new imageobject (RES_DIR, $unique_str, $this->type);
	return $newobject;
}

private function createImage ($new_w, $new_h) {
	if (function_exists ("imagecreatetruecolor") && $this->output != "png8") {
		return imagecreatetruecolor ($new_w, $new_h);
	} else {
		return imagecreate ($new_w, $new_h);
	}
}

private function copyhandle (&$dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
	if ($this->output == "png8" && $this->type = "jpg") {
		imagecopyresized ($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
		$this->resample == true;
	}

	if (function_exists ("imagecopyresampled") && $this->resample == true)
		imagecopyresampled ($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
	else
		imagecopy ($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h);

}

private function copycreatehandle (&$src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
	$dst_im = $this->createImage ($dst_w, $dst_h);
	$this->copyhandle ($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);

	return $dst_im;
}

// public methods
public function resizeImage ($scale, $newwidth = 0, $newheight = 0) {
	$new_w = $this->width;
	$new_h = $this->height;
	$aspect_ratio = (int) $new_h / $new_w;

	if ($scale)
		$new_w = $new_w * $scale;

	if ($newwidth > 0)
		$new_w = $newwidth;

	if ($newheight > 0) {
		$new_h = $newheight;
		$new_w = (int) $new_h / $aspect_ratio;
	} else {
		$new_h = abs ($new_w * $aspect_ratio);
	}

	$dst_img = $this->copycreatehandle ($this->handle, 0, 0, 0, 0, $new_w, $new_h, $this->width, $this->height);

	return $this->createUnique ($dst_img);
}

public function cropImage ($top, $right, $bottom, $left) {
	$new_w = $right - $left;
	$new_h = $bottom - $top;
	$dst_img = $this->copycreatehandle ($this->handle, 0, 0, $left, $top, $new_w, $new_h, $new_w, $new_h);

	return $this->createUnique ($dst_img);
}

public function writeText ($label, $xpos = 0, $ypos = 0, $textstring, $fontsize, $truetype, $fontcolor = "FFFFFF", $fontangle) {
	$fontbgcolor = $this->getHexColor ($xpos, $ypos);
	$textimage = new imagetext ($truetype, $fontsize, $fontcolor, $textstring, $fontbgcolor, $fontangle);
	ImageAlphaBlending ($this->handle, true);
	imagesavealpha ($this->handle, false);
	imagesavealpha ($this->handle, true);
	$this->copyhandle ($this->handle, $textimage->handle, $xpos, $ypos, 0, 0, $textimage->dx, $textimage->dy, $textimage->dx, $textimage->dy);

	return $this->createUnique ($this->handle);
}

public function mergeImage ($dir, $placedfile, $mergewidth, $mergeheight, $offx, $offy, $transcolor = "") {
	$source = new imageobject ($dir, $placedfile);
	$source->saveAlpha ($source->handle);

	if ($transcolor) {
		$r = hexdec (substr ($transcolor, 0, 2));
		$g = hexdec (substr ($transcolor, 2, 2));
		$b = hexdec (substr ($transcolor, 4, 2));
		$color = imagecolorallocate ($source->handle, $r, $g, $b);
		imagecolortransparent ($source->handle, $color);
	}

	$this->saveAlpha ($this->handle);
	ImageCopyResized ($this->handle, $source->handle, $offx, $offy, 0, 0, $mergewidth, $mergeheight, $source->width, $source->height);

	return $this->createUnique ($this->handle);
}
}// class

 

That said, I could not find a single instance of $this being used incorrectly. So you'll want to check that error message a bit closer, as it will tell you exactly on what line of which file the error occurs.

Link to comment
Share on other sites

Thanks a lot, Christian F.

AbraCadaver, I did what you said and these are the errors:

 

Notice: Undefined variable: img_dir in xxx/index.php on line 7

Notice: Undefined variable: uploadedfile in xxx/index.php on line 9

Notice: Undefined variable: backgroundcolor in xxx/index.php on line 18

Notice: Undefined variable: backgroundimage in xxx/index.php on line 21

Notice: Undefined variable: currentimage in xxx/index.php on line 23

Notice: Undefined variable: info in xxx/index.php on line 76

Notice: Undefined variable: info in xxx/index.php on line 82

Notice: Undefined variable: info in xxx/index.php on line 89

Notice: Undefined variable: info in xxx/index.php on line 95
Voeg plaatje in...	
Notice: Undefined variable: info in xxx/index.php on line 102

Notice: Undefined variable: info in xxx/index.php on line 108

 

I have configured config.ini.php with the root to every directory.

<?
// image subdir for standard backgrounds
DEFINE("IMG_DIR","backgrounds/");
// result images - must be writable!
DEFINE("RES_DIR","images/");
// to merge/upload  - must be writable!
DEFINE("MRG_DIR","merge/");
// select merge dialogs etc. - readonly
DEFINE("SEL_DIR","select/");
// truetype font files - readonly
DEFINE("FNT_DIR","ttf/");
// maximum age of result (temp) images
DEFINE("MAXAGE",3);
// default language
DEFINE("LANGUAGE","en");
// default filetype to produce jpg or png
DEFINE("OUTPUT","jpg");
// default positions for images on screen in pixels
// background
$image_default_x = 150;
$image_default_y = 150;
// dropin image
$merge_default_x = 200;
$merge_default_y = 200;
// text preview
$text_default_x = 220;
$text_default_y = 230;

// max script exec time, when needed decomment
//set_time_limit(50);

// memory limit, php default is 8 MB. raising it will permit larger images
ini_set("memory_limit", "16M");


?>

 

And this is index.php

 

<?
include("include/config.inc.php");
include("language/lang.".LANGUAGE.".php");
include("include/image.class.php");
include("include/functions.php");

if (!$img_dir) $img_dir = IMG_DIR;

if ($uploadedfile){

   if (copy($uploadedfile,MRG_DIR.$uploadedfile_name))

   $mergefile = MRG_DIR.$uploadedfile_name;
   $mergefilename = $uploadedfile_name;
   $merge = new imageobject(MRG_DIR,$uploadedfile_name);
   }

if ($backgroundcolor && $width && $height){
   $new = new imageobject(IMG_DIR,"",$width,$height,$backgroundcolor);
   if ($new->newobj) $info = $new->newobj;
} elseif ($backgroundimage){
   $info = new imageobject(IMG_DIR,$backgroundimage);
} elseif ($currentimage){

   $img = splitDirFile($currentimage);

   $info = new imageobject($img[0], $img[1]);

   if ($mailto)
    include("include/mailimage.php");
    else{
    if ($placedmerge && !$uploadedfile){
        $mrg = splitDirFile($placedmerge);
        $offx = $xmerge - $ximg;
        $offy = $ymerge - $yimg;
        $info = $info->mergeImage($mrg[0],$mrg[1],$mergewidth,$mergeheight,$offx,$offy);
        unset($placedmerge);
        }
    if ($textstring){
        if (!$currentlabel)$currentlabel = $currentimage;
        $offx = $textxpos - $ximg;
        $offy = $textypos - $yimg;
        $info = $info->writeText($currentlabel, $offx, $offy, $textstring, $fontsize, $truetype, $fontcolor, $fontangle);
        }
    }// mailto else

}else{
     deleteOldFiles();
     }

?>
<html>
<head>
    <title><?=TITLE?></title>
<?
include("include/dragdrop.js.php");
include("templates/style.css.php");
?>
<body onload="libinit();">

<table width="100%" class="white" cellspacing="2" cellpadding="2">
  <tr>

    <td width="28" nowrap align="center">
      <A href="#" onclick="objopen.showIt()">
         <img src="templates/images/color.gif" border="0">
      </A>
    </td>
    <td>
      <A href="#" onclick="objopen.showIt()">
         <?=LANG_CHOOSE?>
      </A>
    </td>

    <td width="28" nowrap align="center" border="0">
        <? if ($info){ ?>
        <A href="#" onclick="objtext.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <img src="templates/images/font.gif" border="0">
        </A>
    </td>
    <td>
        <? if ($info){ ?>
        <A href="#" onclick="objtext.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <?=LANG_ADDTEXT?>
        </A>
    </td>

    <td width="28" nowrap align="center">
        <? if ($info){ ?>
        <A href="#" onclick="objupload.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <img src="templates/images/merge.gif" border="0">
        </A>
    </td>
    <td>
        <? if ($info){ ?>
        <A href="#" onclick="objupload.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <?=LANG_UPLOADLOGO?>
        </A>
    </td>

    <td width="28" nowrap align="center">
        <? if ($info){ ?>
        <A href="#" onclick="objfinish.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <img src="templates/images/save.gif" border="0">
        </A>
    </td>
    <td>
        <? if ($info){ ?>
        <A href="#" onclick="objfinish.showIt()"><?}else{?><A href="#" onclick="alert('<?=LANG_FIRST?>')"><?}?>
        <?=LANG_FINISHED?>
        </A>
    </td>

    <td>TrueColor MyCanvas<BR/><A href="http://allayers.com">© ALLAYERS.COM</A></td>
  </tr>
</table>


<?
include("templates/dialogs.dhtml.php");
?>


<?if($message) echo "<div align=\"center\">$message</div>"; ?>

<div id="previewdiv" onclick="setTextPreviewXY()">
  <img name="previewimage" id="previewimage">
</div>

<div id="lefttopdiv" onclick="showResize()">
</div>

<div id="rightbottomdiv" onclick="showResize()">
</div>

<div id="imgdiv" onclick="setImagePos()">
  <IMG id="mainimg"<? if ($info) echo " src=\"".$info->directory.$info->filename."\" ".$info->string; ?>>
</div>

<div id="mergediv" onmousemove="setMergePos()">
  <IMG id="mergeimg"<? if ($mergefile) echo " src=\"".$mergefile."\""; ?>>
</div>

</body>
</html>

 

 

Link to comment
Share on other sites

3.5 hours on an international forum is not a whole lot of time, especially considering that people using this forum come from all over the world. Give it at least 2 days before bumping, as that should give everyone enough time to read, think and respond.

 

That said: The "errors" you've listed are not errors, their notices. Had they been errors, the script would have failed at the first.

You should still work to fix them, seeing as they can lead to problems later on. Most of all, because having notices like this is a sign of sloppy coding.

If you don't know what the message "undefined variable" means, then I recommend a search for it on the net. It's a fairly straight forward message, with a very logical cause.

Link to comment
Share on other sites

Since I'm short on time, I'll help you with one of the errors. Take the lead after this, go through your code, and ask yourself where it could go wrong.

 

Notice: Undefined variable: img_dir in xxx/index.php on line 7

 

7| if (!$img_dir) $img_dir = IMG_DIR;

 

$img_dir was never instantiated. Your code says, "if $img_dir is not true, set it to IMG_DIR." Because $img_dir never existed, the server is says, "Hey! I'm supposed to check this variable, $img_dir, but it doesn't exist."

 

To fix it, ask if it's empty, or isset.

if(empty($img_dir) $img_dir = IMG_DIR;

 

You can shorten it into a variable declaration, if you'd like.

$img_dir = empty($img_dir) ? IMG_DIR : $img_dir;

 

That last one says, $img_dir equals, if $img_dir is empty, IMG_DIR, otherwise, $img_dir

Link to comment
Share on other sites

3.5 hours on an international forum is not a whole lot of time, especially considering that people using this forum come from all over the world. Give it at least 2 days before bumping, as that should give everyone enough time to read, think and respond.

 

OK. Good answer, must be mor pacient I suppose...

 

I have been looking  on the net what those notices are. And as you say, not errors. I will wait for something that can help me

 

Link to comment
Share on other sites

Since I'm short on time, I'll help you with one of the errors. Take the lead after this, go through your code, and ask yourself where it could go wrong.

 

Notice: Undefined variable: img_dir in xxx/index.php on line 7

 

7| if (!$img_dir) $img_dir = IMG_DIR;

 

$img_dir was never instantiated. Your code says, "if $img_dir is not true, set it to IMG_DIR." Because $img_dir never existed, the server is says, "Hey! I'm supposed to check this variable, $img_dir, but it doesn't exist."

 

To fix it, ask if it's empty, or isset.

if(empty($img_dir) $img_dir = IMG_DIR;

 

You can shorten it into a variable declaration, if you'd like.

$img_dir = empty($img_dir) ? IMG_DIR : $img_dir;

 

That last one says, $img_dir equals, if $img_dir is empty, IMG_DIR, otherwise, $img_dir

 

There's number one.

 

 

Before we continue, let's check out the empty($var) function.

It returns true or false, based on the argument passed to it.

Returns FALSE if var exists and has a non-empty, non-zero value. Otherwise returns TRUE.

 

The following things are considered to be empty:

 

"" (an empty string)

0 (0 as an integer)

0.0 (0 as a float)

"0" (0 as a string)

NULL

FALSE

array() (an empty array)

$var; (a variable declared, but without a value)

 

Notice: Undefined variable: uploadedfile in xxx/index.php on line 9

9| if ($uploadedfile){

You have yet to define this variable. I assume you want to check if it is true? Use !empty().

if(!empty($uploadedfile) {

 

 

Notice: Undefined variable: backgroundcolor in xxx/index.php on line 18

18| if ($backgroundcolor && $width && $height){

Again, you have not defined the variable. Use empty().

if(!empty($backgroundcolor) && !empty($width) && !empty($height)) {

 

Notice: Undefined variable: backgroundimage in xxx/index.php on line 21

I refuse to go on about this.

 

Notice: Undefined variable: currentimage in xxx/index.php on line 23

 

Notice: Undefined variable: info in xxx/index.php on line 76

 

Notice: Undefined variable: info in xxx/index.php on line 82

 

Notice: Undefined variable: info in xxx/index.php on line 89

 

Notice: Undefined variable: info in xxx/index.php on line 95

Voeg plaatje in...

Notice: Undefined variable: info in xxx/index.php on line 102

 

Notice: Undefined variable: info in xxx/index.php on line 108

 

----

 

Every single error you have is the exact same. Read up on empty().

Link to comment
Share on other sites

maxudaskin, I made what you said and all notices dissapear.

I'm trying to run on my web this application made in PHP:

 

http://allayers.com/mycanvas/

 

It would be perfect for my site, with some modifications, but as I know there are problems when running under PHP5, although it is supposed to be fixed in the last version. The download page of last version is http://truecolor.allayers.com/, if anyone could make it work on PHP 5...

Link to comment
Share on other sites

make it work

 

Since you haven't specifically stated exactly what the script is doing that leads you to believe it doesn't work, no one here can help you based on the information you have supplied. If you want specific help with a program, you must supply the specific symptoms or errors that you need help with.

 

You started this thread by adding your post to an existing thread, where you implied that you were getting the same error as in the title - "Cannot re-assign $this". But there is no indication at all that you were getting that error.

 

The list of undefined variable notices 'could' prevent a script from working if that script was trying to use header() statements, sessions, or cookies... But again, nothing you have supplied indicates what is or is not working.

 

We are not here to rewrite poorly written 3rd party scripts for people who want to use them, and since this is a 3rd party script, moving this thread to the appropriate forum section...

Link to comment
Share on other sites

I am not a PHP expert, so I don't exactly know what the problem with these scripts.

I configure the file config. inc. php, and that is suppossed to be the the only one to be customized.

The rest of the script are files that don't have to be moddified.

 

When I enter to my index.php page, and I try to load  background (the first thing you have to do), the page reloads but no image loads. So the the application stops in that point.

 

This is mycanvas home page:

http://allayers.com/mycanvas/

 

And this is mine one:

http://www.yasoymama.com/mycanvas/

 

As you can see, something is wrong, and I can't solve the problem

 

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.