<?
include_once "setup.php";
if (isset($addimage) && $addimage=="new_image")
 {
     $flag=1; //if all is ok 
	      if(file_exists("$dir_to_upload/$file1zz_nes_name")) 
              	{
                       print ("File Exist<br>");
                       $flag=0;
                }

		     if ($file1zz_nes_size > $max_upload_size) 
			 {
			  print ("File too big.Size : $file1zz_nes_size<br>");
                          $flag=0;
			 }
		     if ($file1zz_nes_size < 3000) //minimum size is 3 kb
			 {
			  print ("File too small.Size : $file1zz_nes_size<br>");
                          $flag=0;
			 }
		     if ($file1zz_nes_type !="image/pjpeg" && $file1zz_nes_type !="image/gif" && $file1zz_nes_type !="image/jpeg" && $file1zz_nes_type !="image/png" )
			{
			  print ("It's not image<br>");
                          $flag=0;   
			}
	       switch($file1zz_nes_type)
	       {
                     case "image/pjpeg": 
	             case "image/jpeg":
                     $ext="jpg";   
                     break;
                     case "image/gif": 
                     $ext="gif";   
                     break;
                     case "image/png": 
                     $ext="png";   
                     break;

	       }
	      if ($flag)
	      {
                   $file_to_save=$lastid.".".$ext; //id that product got whan was added
		   if (copy($file1zz_nes,"$dir_to_upload/$file_to_save")) 
		   {
                     $result=1;
                     $result=$result+mysql_query("
                     update product set
                     Photo='$file_to_save'
                     where ID=$lastid
                     ") or die (mysql_error(). " : ".mysql_errno());
		   } 
                   else 
                     {
              	      print('Error uploading file. Are directory permissions amenable ?<br>');
                     }
                     //echo $result." ".$lastid;
	      }
             if ($result==2)
             {
              echo "Photo was submitted sucsessfully<br>";
              echo "<img src='$dir_to_upload/$file_to_save'>";
              exit;
             }
              else 
		{
                     print 'No file was submitted';
                }

}
?>

<form name='image' method=post action=upload.php ENCTYPE="multipart/form-data">
<input type=hidden name=lastid value=<?=$lastid;?>>
<input type=hidden name=addimage value='new_image'>
Choose Image: <input name="file1zz_nes" type="file" size="30"> 
<input type="submit" value="Upload File" onclick="return validate_form_no_email('image')">
</form>
