0

I created a form to upload into a MySQL table text data and images' paths. The images are uploaded and stored in folders of the server. It worked perfect till i used php session. I used PHP session_start at the begining of the code (for access through username and password) and then it does not import data to the database. It displays an error of "Fatal error: Call to undefined function resizeImage()" on line 84.

Any recomendations to find out why the function resizeImage() doesn't work when I add session_start?

file: eis-post2.php

<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<title>Upload form</title>
</head>

<body> 

<form name='newad' method='post' enctype='multipart/form-data'  action=".$_SERVER['PHP_SELF'].">
 <table>
<tr><td>title:</td><td><input type='text' name='title'></td></tr>
<tr><td>date</td><td><input type='date' name='date'></td></tr>
<tr><td>descriptionΠεριγραφή:</td><td><input type='text' name='desc'></td></tr>
<tr><td>sourse</td><td><input type='text' name='author'></td></tr>
<tr><td>Main text</td><td><textarea  name='maintext' id='maintext' required=''></textarea></td></tr>
<tr><td>Image</td><td><input type='file' name='image'></td></tr>
<tr><td>&nbsp;</td><td><input name='Submit' type='submit' value='Upload image'></td>    </tr>
 </table> 
 </form>
 </body>
</html>";

 define ("MAX_SIZE","500"); 


 function getExtension($str) {
     $i = strrpos($str,".");
     if (!$i) { return ""; }
     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
 }

 $errors=0;

if(isset($_POST['Submit'])) 
{


$image=$_FILES['image']['name'];
$image=uniqid() . '.jpg';


if ($image) 
{

    $filename = stripslashes($_FILES['image']['name']);

    $extension = getExtension($filename);
    $extension = strtolower($extension);



if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) 
    {

        echo '<h1>Unknown extension!</h1>';
        $errors=1;
    }
else
    {


        $size=filesize($_FILES['image']['tmp_name']);


        if ($size > MAX_SIZE*2048)
        {
            echo '<h1>You have exceeded the size limit!</h1>';
            $errors=1;
        }

        else {


        $temp=resizeImage($_FILES['image']['tmp_name'],270,230);
        $imgfile="images/small/".$image;
        imagejpeg ( $temp, $imgfile );

        $temp2=resizeImage($_FILES['image']['tmp_name'],480,330);
        $imgfile2="images/big/".$image;

        imagejpeg ( $temp2, $imgfile2 );

        }


    }
}

else
{
    echo "<h1>Select Image File</h1>";
    $errors=1;
}
}


 if(isset($_POST['Submit']) && !$errors) 
 {
echo "<h1>File Uploaded Successfully! Try again!</h1>";
include('db.php');

mysql_query("SET NAMES 'utf8'");


$title=$_POST['title'];
$date=$_POST['date'];
$desc=$_POST['desc'];
$author=$_POST['author'];
$maintext=$_POST['maintext'];

$query="insert into post( small_img, big_img, title, date, description, post_text, post_author) 
values( '$imgfile', '$imgfile2', '$_POST[title]', '$_POST[date]', '$_POST[desc]','$_POST[author]', '$_POST[maintext]' )";

$result=mysql_query($query);

if ($result)
{
echo "Information stored successfully";
}
else
{
echo mysql_error();
}

 }



function resizeImage($imgSrc,$thumbnail_width,$thumbnail_height) { 

list($width_orig, $height_orig) = getimagesize($imgSrc);   
$myImage = imagecreatefromjpeg($imgSrc);
$ratio_orig = $width_orig/$height_orig;

if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
   $new_height = $thumbnail_width/$ratio_orig;
   $new_width = $thumbnail_width;
} else {
   $new_width = $thumbnail_height*$ratio_orig;
   $new_height = $thumbnail_height;
}

$x_mid = $new_width/2;  //horizontal middle
$y_mid = $new_height/2; //vertical middle

$process = imagecreatetruecolor(round($new_width), round($new_height)); 

imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height); 
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);

imagedestroy($process);
imagedestroy($myImage);
return $thumb;
}



}
else {
die("you must be logged in!");
}
?>

0 Answers0