Php 无法上载数据库中的文件
我正在上载数据库中的PDF文件,但存在一些问题所有数据都已成功上载,但无法上载数据库中的文件 控制器Php 无法上载数据库中的文件,php,codeigniter,Php,Codeigniter,我正在上载数据库中的PDF文件,但存在一些问题所有数据都已成功上载,但无法上载数据库中的文件 控制器 function register_candidate(){ if($this->input->post()){ if ( ! $this->upload->do_upload('resume')) { $filename = '';
function register_candidate(){
if($this->input->post()){
if ( ! $this->upload->do_upload('resume'))
{
$filename = '';
}
else
{
$filename = $this->upload->data('file_name');
}
$dataArray = array('salutation'=>$this->input->post('salutation',true),
'candidate_first_name'=>$this->input->post('candidate_first_name',true),
'candidate_last_name'=>$this->input->post('candidate_last_name',true),
'nationaity'=>$this->input->post('nationaity',true),
'candidate_phone'=>$this->input->post('candidate_phone',true),
'candidate_email'=>$this->input->post('candidate_email',true),
'candidate_job_title'=>$this->input->post('candidate_job_title',true),
'salary'=>$this->input->post('salary',true),
'candidate_password'=>md5($this->input->post('candidate_password', true)),
'resume'=>$filename
);
//print_r($dataArray);
if($this->Candidate_model->register_candidate($dataArray)){
$this->session->set_flashdata('success', 'Data Successfully Inserted');
redirect('Candidate/register_candidate');
}else{
$this->session->set_flashdata('error', 'Failed to insert');
redirect('Candidate/register_candidate');
}
}else{
$this->load->view('frontend/header');
$this->load->view('home/register_user');
$this->load->view('frontend/footer');
}
}
只有上载数据时出现问题,因为文件无法上载,并且其在数据库中显示空白数据请勿将文件上载到数据库。在项目文件夹中创建文件夹并将pdf上载到其中。然后,您可以插入数据库的文件名和文件路径作为引用
$time_snamp = date('Ymdhisu');
$filename = $_FILES["file"]['name'];
$filename = $time_snamp . '_' . $filename;
$file = $_FILES["file"]['name'];
$targetPath = 'uploads/Targets/' . $filename;
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);
使用此选项上载文件文件上载类 CodeIgniter的文件上传类允许上传文件。你 可以设置各种首选项,限制文件的类型和大小 档案 控制器:
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the ``initialize()`` method. Useful if you auto-load the class:
$this->upload->initialize($config);
加载上载库:
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the ``initialize()`` method. Useful if you auto-load the class:
$this->upload->initialize($config);
设置首选项:
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
$this->load->library('upload');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
// Alternately you can set preferences by calling the ``initialize()`` method. Useful if you auto-load the class:
$this->upload->initialize($config);
上述偏好应该是不言自明的。下面是一个例子
描述所有可用首选项的表
我从没见过有人把文件上传到数据库里,我想你搞错了。您“上载”到web主机上的文件夹中的文件,以及文件到数据库中的“路径”,而不是整个文件…旁注:md5不是安全的哈希,不要将其用作密码。使用
password\u hash
——如果您可以使用password\u ARGON2I
作为算法。