我想在php中使用fileupload()
函數上傳PDF文件。當沒有會話被使用但是會話出錯時,這很好用。
在php中fileupload()不會與會話
我這是怎麼定義的會話:
session_start();
if(isset($_SESSION['name']))
{
$name=$_SESSION['name'];
$_SESSION['name']=$name;
這裏是文件上傳()函數:
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
}}
這是錯誤消息我得到:
Fatal error: Call to undefined function fileupload() in C:\wamp\www...\course_submit_process.php on line 66
我檢查了一切錯誤,但找不到任何解決方案。請讓我知道如果我失去了一些東西。
在此先感謝。
您認爲這與會話有什麼關係?我認爲這有點讓人困惑:錯誤是'未定義的函數fileupload',這是一個提示:) – Nanne
$ name = $ _ SESSION ['name']; $ _SESSION ['name'] = $ name;沒有多大意義? – jtheman
是的,它是'未定義的函數錯誤不是會話' –