我必须将所有文件上传到我的数据库中。我的数据库在服务器上可用。目前我正在尝试上传pdf文件,但我无法上传 它。我尝试了谷歌的许多代码,但到目前为止还没有为我工作的代码。如何将pdf文件上传到我的数据库?
<?php
if(isset($_POST["submit1"]))
{
echo $filename = basename($_FILES['healthfile']['name']);
$newname = $folder_path . $filename;
$FileType = pathinfo($newname,PATHINFO_EXTENSION);
if($FileType == "pdf")
{
if (move_uploaded_file($_FILES['healthfile']['tmp_name'], $newname))
{
$filesql = "INSERT INTO user(pdf) VALUES('$filename') WHERE id='$id'";
$query = mysqli_query($conn, $filesql);
if (isset($query))
{
echo 'File Uploaded';
} else
{
echo 'Something went Wrong';
}
}
else
{
echo "<p>Upload Failed.</p>";
}
}
else
{
echo "<p>Class notes must be uploaded in PDF format.</p>";
}
}
?>
答案 0 :(得分:0)
我认为如果定义了$ id,你应该进行UPDATE而不是INSERT INTO:
<?php
if(isset($_POST["submit1"]))
{
echo $filename = basename($_FILES['healthfile']['name']);
$newname = $folder_path . $filename;
$FileType = pathinfo($newname,PATHINFO_EXTENSION);
if($FileType == "pdf")
{
if (move_uploaded_file($_FILES['healthfile']['tmp_name'], $newname))
{
$filesql = "UPDATE user SET pdf ='$filename' WHERE id='$id'";
$query = mysqli_query($conn, $filesql);
if (isset($query))
{
echo 'File Uploaded';
} else
{
echo 'Something went Wrong';
}
}
else
{
echo "<p>Upload Failed.</p>";
}
}
else
{
echo "<p>Class notes must be uploaded in PDF format.</p>";
}
}
?>