Bushra Shahid
Bushra Shahid

Reputation: 781

fileupload() in php not working with session

I am trying to upload a pdf file using fileupload() function in php. This works great when no session is used but gives an error with session.

This is how I defined a session:

 session_start();
if(isset($_SESSION['name']))
{
$name=$_SESSION['name'];
$_SESSION['name']=$name;


and here is the fileupload() function:

function fileupload()
{
$corname = $_POST['corname'];
 define ("FILEREPOSITORY","./upload");

$filename = './upload/'.$corname.'.pdf';
//echo $filename;

   if (is_uploaded_file($_FILES['file']['tmp_name'])) 
   {

      if ($_FILES['file']['type'] != "application/pdf") 
      {
         echo "<p>Class notes must be uploaded in PDF format.</p>";
      } 


     else if(file_exists($filename))
        {
      echo "already exist";
       }

        else 
      {
         //$name = $_POST['corname'];
         $result = move_uploaded_file($_FILES['file']['tmp_name'], FILEREPOSITORY."/$corname.pdf");
         if ($result == 1) 
            {echo "<p>File successfully uploaded.</p>";
            $cata=$_POST['cata'];
$subcata=$_POST['subcata'];
$corname = $_POST['corname'];
$heading=$_POST['headng'];
$descrip=$_POST['descrip'];
$cno=$_POST['cno'];
$credit=$_POST['credit'];
$fee=$_POST['fee'];
            $qry="insert into course (catagory,subcatagory,courseno,coursename,heading,description,credit,fee,coursefilename) values ('$cata','$subcata','$cno','$corname','$heading','$descrip','$credit','$fee','$corname')";
$ins_qry=mysql_query($qry);
if($ins_qry)
{
echo "Successfully Inserted<br>";
}
else
{
echo mysql_error();
}}
         else {echo "<p>There was a problem uploading the file.</p>";}
       } #endIF
   } #endIF

}}

This is the error message I get:

Fatal error: Call to undefined function fileupload() in C:\wamp\www...\course_submit_process.php on line 66


I have checked everything for some error but can't reach for any solution. Please let me know if I am missing something.
Thanks in advance.

Upvotes: 1

Views: 319

Answers (2)

jtheman
jtheman

Reputation: 7491

In the code posted you don't end the first IF condition with }. That might cause your problem if the fileupload() function follows.

An 'undefined' function has nothing to to whether you initiated PHP sessions or not. So look into the error message instead. 'Undefined' error happens when the function is unknown at the point when the function is first called.

Upvotes: 1

Geert
Geert

Reputation: 1227

You didn't include the file that has the fileupload() method in it.

So on top of course_submit_process.php:

include "file_containing_fileupload()";

Upvotes: 1

Related Questions