我正在使用Mysql DB上载PDF文件,但该PDF文件未写入数据库中,如图所示 enter image description here
<?php
//include the PDF files inside the DB
if (isset($_POST['reg_user'])) {
$arq = $_FILES['pdf_upload']['name'];
$arq = str_replace(" ", "_", $arq);
$target = "pdf/";
$yes = "yes";
$fileTarget = $target.$arq;
$tempFileName = $_FILES["pdf_upload"]["tmp_name"];
//$allow=array('pdf');
//$temp=explode(".",$arq);
//$extension=end($temp);
$digits = 3;
$random = rand(pow(10, $digits-1), pow(10, $digits)-1);
move_uploaded_file($tempFileName,$fileTarget);
//$qry = mysqli_query($db,"INSERT INTO 'pp_seeker_resumes'(file_name)VALUES('$arq');");
if($result) {
header('location: success.php');
$qry = "INSERT INTO pp_seeker_resumes(seeker_ID,is_uploaded_resume,file_name)VALUES('$random','$yes','$arq');";
$db->query($qry) or die("Error : ".mysqli_error($db));
}
else {
echo "Sorry !!! There was an error in uploading your file";
}
//mysqli_close($db);
/*if($qry){
echo "PDF File upload success";
}else{
echo "upload Error !! ";
}*/
}
?>
这里$ db是我在server.php中建立的连接,它工作正常。 这是HTML表单的一部分
<label style="margin:12px">Upload CV(.pdf)</label>
<input type="file" class="form-control" name="pdf_upload"
id="fileHelp" aria-describedby="fileHelp" accept="application/pdf">
这里的success.php是表单填写后加载的页面。
谢谢您的帮助。
答案 0 :(得分:0)
感谢cloudinary文档,我找到了原因 这应该添加到HTML表单中
enctype="multipart/form-data"
使用post方法无法上传此文件,因此应这样做
<form method = "post" action="member_form1.php" enctype="multipart/form-data">
<label style="margin:12px">Upload CV(.pdf)</label>
<input type="file" class="form-control" name="pdf_upload"
id="fileHelp" aria-describedby="fileHelp" accept="application/pdf">