1

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.

4
  • Why do you think this has anything to do with a session? I think that confuses the matter a bit: the error is undefined function fileupload, that's a hint :) Commented Oct 23, 2012 at 6:50
  • $name=$_SESSION['name']; $_SESSION['name']=$name; doesnt make much sense? Commented Oct 23, 2012 at 6:52
  • yes, it is undefined function error not session Commented Oct 23, 2012 at 7:03
  • where you put fileupload()? if it is not in course_submit_process.php, have you include the file? Commented Oct 23, 2012 at 7:04

2 Answers 2

1

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()";
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.