doumaogui5937
doumaogui5937
2018-10-27 09:33
采纳率: 100%
浏览 47
已采纳

使用PHP将文件上传到Mysql中,但不会在DB上显示[重复]

This question already has an answer here:

I am using Mysql DB to upload a PDF file in but the PDF file is not written in DB as in picture 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 !! ";
}*/
}
?>

Here $db is the connection I have made in server.php ,It works fine. This is the HTML form part

<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"> here success.php is the page loaded after form filling. Thankyou for your help.

</div>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtnpf35197
    dtnpf35197 2018-10-27 09:49
    已采纳

    Thanks to cloudinary documentation,I found the reason this should be added to the form in HTML

    enctype="multipart/form-data"
    

    without this file upload is not possible with post method,thus this should be done

    <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">
    
    点赞 评论

相关推荐