<?php
//#******************************************************************************************************************
if (isset ($_REQUEST['imgm']) or isset ($_REQUEST['pimg'])  or isset ($_REQUEST['imgb']))  //
//*******************************************************************************************************************
{
if ($_FILES['new']['name']!="") 
 {if (is_uploaded_file($_FILES['new']['tmp_name']))
{
$mti=array("GIF" =>1,"JPG" =>2,"JPEG" =>2,"PNG" =>3,"SWF" =>4,"PSD" =>5,"BMP" =>6,"TIFF_II" =>7,"TIFF_MM" =>8,"JPC" =>9,
 "JP2" =>10,"JPX" =>11,"JB2" =>12,"SWC" =>13,"IFF" =>14,"WBMP" =>15,"XBM" =>16); 
$mpi=getimagesize($_FILES['new']['tmp_name']);          //
list($nad1,$exp)=explode('.',$_FILES['new']['name']);   //
$exp=strtoupper ($exp);                                 //
// 
if ($mti[$exp]!=$mpi[2])
{$os= "<b style=color:red>Mismatch in picture extension ".$exp.", type ". array_search($mpi[2], $mti)."</b>"; 
}
else
{$size_img=GetImageSize($_FILES["new"]["tmp_name"]);
 $width=$size_img[0] ;                  //
 $height=$size_img[1] ;                 //
 $nus=$_REQUEST['row']; 			    //
 $col=$_REQUEST['col'];				    //
 if ($col!="")  					    //
 {$l = file($_frhtm); 				    //
//echo  htmlspecialchars($_frhtm, ENT_QUOTES);  

  $w = fopen($_frhtm, 'w') or exit;     //
   foreach ($l as $li => $lin)          //
    {if ($li==$nus)  				    //
     {$mtag = explode("<", $lin);	
	 foreach ($mtag as $ti => $tag)      //
{
//echo  htmlspecialchars($tag, ENT_QUOTES);  
if (strstr($tag,"alt=".trim($col)." ")) 
{$timg=trim($_REQUEST['html']);   		  //
	 if (isset ($_REQUEST['imgm']))       //
     {$timg=str_replace("<img ","<img height=".$height." width=".$width." ",$timg);  //
     } 
  if (strtoupper(substr($mtag[$ti-1],0,2))=="A ")   //
     {$mtag[$ti-1]="*";
     $mtag[$ti+1]="*";
	 }
	 list($nad1,$exd1)=explode('.',$_FILES['new']['name']);   //
     $izf=tr($nad1).".".$exd1;                                //
	 $izf=strtolower($izf);                                   //
	 $izf=str_replace(" ","_",$izf);
     $izfo=$_FILES['new']['name'];
	 $izfo=str_replace(" ","_",$izfo);
	 $timg=str_replace($izfo,$izf,$timg);       //
     $mtag[$ti]=substr($timg,1);                //
//
	 $fk=$_prhtm.'/'.$izf;   //
      if (copy($_FILES["new"]["tmp_name"],$fk)) //
     {}
 	 else
	 {$os=$os. "<b>Copy error</b>";fwrite($w,$sw);
	 }}}
	$tn="";                                      // 
foreach ($mtag as $ti => $tag)                   // 
{if ($tag=="*")
{}
else
{$tn=$tn."<".$tag;}
}	
$tn=substr($tn,1);                               // 
fwrite($w,stripslashes($tn));                    // 
	}
    else {fwrite($w,stripslashes($lin));}        // 
    } 
    fclose($w);
	if (isset ($_REQUEST['imgm'])) 
	{$os=$os. '<b style="color:green">Small picture uploaded and inserted into the page!</b>';
	}
	if (isset ($_REQUEST['pimg']))  
	{$os=$os. '<b style="color:green">The big picture that opens when you click in the current window is loaded and inserted into the page!</b>';
	}
	if (isset ($_REQUEST['imgb']))
	{$os=$os. '<b style="color:green">The big picture that opens on click in a separate window is loaded and inserted into the page!</b>';
	}}
	else
{$os=$os. '<b style="color:red">No picture selected! Select it with a click and repeat!</b>';
}}
else
{
$os=$os. '<b style="color:red">Picture file not loaded?</b>';
}
}
else
{$os=$os. '<b style="color:red">The size of the selected picture file is more than 2 MB! Make it smaller and repeat!</b>';
}}
else
{$os=$os. '<b style="color:red">No picture selected! Click "Browse ...", select the picture file and repeat!</b>';
}} 

