-2

Undefined variable error is occurring while opening the php page in browser. Here example of image validation: No error in validating & Uploading the image., but i can't solve the Undefined variable error. plz help me.

<?
if(isset($_POST['save'])){
$rand=rand().time();
$photo_name=$_FILES['photo']['name'];
$photo_tmp_name=$_FILES['photo']['tmp_name'];
$photo_name=explode(".",$photo_name);
list($width,$height) = getimagesize($photo_tmp_name);
if($photo_name[1]=="jpeg"||$photo_name[1]=="jpg"||$photo_name[1]=="gif")
{
    if($width<=365)
    {
        $photo_name=$photo_name[0].$rand.".".$photo_name[1];
        move_uploaded_file($photo_tmp_name,"Images/{$photo_name}");
    }
    else
    {   $sz_err="Not correct Perfect Size"; }
}
else
{   $tp_err="Not correct Type";         }   
}

//These two Bold Variables are "echo/print" in the body tag of the html. But Error occurring in the HTML LINE ONLY.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95
Sathya Velan
  • 1
  • 2
  • 6

1 Answers1

-1

Just Try With The Following :

PHP Part :

<?php
$sz_err="";
$tp_err="";
if(isset($_POST['save'])){
$rand=rand().time();
$photo_name=$_FILES['photo']['name'];
$photo_tmp_name=$_FILES['photo']['tmp_name'];
$photo_name=explode(".",$photo_name);
list($width,$height) = getimagesize($photo_tmp_name);
if($photo_name[1]=="jpeg"||$photo_name[1]=="jpg"||$photo_name[1]=="gif")
{
if($width<=365)
{
$photo_name=$photo_name[0].$rand.".".$photo_name[1];
move_uploaded_file($photo_tmp_name,"Images/{$photo_name}");
}
else
{ 
$sz_err="Not correct Perfect Size"; 
}
}
else
{ 
$tp_err="Not correct Type"; 
}
}
?>

I think this may help you to resolve your problem.

John Peter
  • 2,870
  • 3
  • 27
  • 46
  • 1
    This is wrong, Those vars are being declared before any use and would not be the ones causing the error. – kittycat Mar 29 '13 at 06:59
  • 1
    where they declared, did you seen any where in the given code ? and then which causing the error in the above code ? – John Peter Mar 29 '13 at 07:04
  • 1
    Are you looking at the same code?!?! `$sz_err="Not correct Perfect Size";` and `$tp_err="Not correct Type";` See the `=` signs that means they are being declared and set to a value. – kittycat Mar 29 '13 at 07:05
  • 1
    I think you didn't understand the PHP codings / logics, if you are assigning variable values inside the if(isset($_POST['save'])){ //codes } conditions means how could you access in HTML Part ? Is it possible ? Image Upload
    – John Peter Mar 29 '13 at 07:11
  • Did you understand what i'm trying to explain to you and user ? – John Peter Mar 29 '13 at 07:12
  • 1
    Are you asking is it possible to access those vars outside of the `if/else` statements? Is so, yes as they are in the global scope. – kittycat Mar 29 '13 at 07:13
  • @cryptic In the above code(Sathya Velan) where they assigned in global ? – John Peter Mar 29 '13 at 07:19