سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top