我想使用php codeigniter在mysql数据库中上传文件。当我上传文件时,它没有显示任何错误,文件也没有上传。而mysql中列file_name的值显示为NULL。 这是我的观看代码:
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('diagnosis_report');?></span></div>
<div class="box-content">
<table cellpadding="0" cellspacing="0" border="0" class="table table-normal ">
<thead>
<tr>
<td><div>#</div></th>
<td><div><?php echo get_phrase('report_type');?></div></td>
<td><div><?php echo get_phrase('document_type');?></div></td>
<td><div><?php echo get_phrase('download');?></div></td>
<td><div><?php echo get_phrase('description');?></div></td>
<td><div><?php echo get_phrase('date');?></div></td>
<td><div><?php echo get_phrase('laboratorist');?></div></td>
<td><div><?php echo get_phrase('option');?></div></td>
</tr>
</thead>
<tbody>
<?php
$count = 1;
$diagnostic_reports = $this->db->get_where('diagnosis_report' , array('prescription_id' => $prescription_id))->result_array();
foreach($diagnostic_reports as $row2):?>
<tr>
<td><?php echo $count++;?></td>
<td><?php echo $row2['report_type'];?></td>
<td><?php echo $row2['document_type'];?></td>
<td style="text-align:center;">
<?php if($row2['document_type'] == 'image'):?>
<div id="thumbs">
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>"
style="background-image:url(<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>)" title="<?php echo $row2['file_name'];?>">
</a></div>
<?php endif;?>
<a href="<?php echo base_url();?>uploads/diagnosis_report/<?php echo $row2['file_name'];?>" target="_blank"
class="btn btn-blue"> <i class="icon-download-alt"></i> <?php echo get_phrase('download');?></a>
</td>
<td><?php echo $row2['description'];?></td>
<td><?php echo date('d M,Y', $row2['timestamp']);?></td>
<td><?php echo $this->crud_model->get_type_name_by_id('laboratorist',$row2['laboratorist_id'],'name');?></td>
<td align="center">
<a href="<?php echo base_url();?>index.php?laboratorist/manage_prescription/delete_diagnosis_report/<?php echo $row2['diagnosis_report_id'];?>/<?php echo $prescription_id;?>" onclick="return confirm('delete?')"
rel="tooltip" data-placement="top" data-original-title="<?php echo get_phrase('delete');?>" class="btn btn-red">
<i class="icon-trash"></i>
</a>
</td>
</tr>
<?php endforeach;?>
</tbody>
</table>
</div>
</div>
<!------DIAGNOSTIC REPORT FOR THIS PRESCRIPTION---->
<!------ADD A DIAGNOSTIC REPORT TO THIS PRESCRIPTION-->
<div class="box">
<div class="box-header"><span class="title"><?php echo get_phrase('add_diagnosis_report');?></span></div>
<div class="box-content">
<?php echo form_open('laboratorist/manage_prescription/create_diagnosis_report' , array('class' => 'form-horizontal validatable'));?>
<div class="padded">
<div class="control-group">
<label class="control-label"><?php echo get_phrase('report_type');?></label>
<div class="controls">
<input type="text" name="report_type" /> <span class="label label-blue">report type can be x-ray, blood-test etc.</span>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('document_type');?></label>
<div class="controls">
<select name="document_type" >
<option value="image"><?php echo get_phrase('image');?></option>
<option value="doc" ><?php echo get_phrase('doc');?></option>
<option value="pdf"><?php echo get_phrase('pdf');?></option>
<option value="excel"><?php echo get_phrase('excel');?></option>
<option value="other"><?php echo get_phrase('other');?></option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('upload_document');?></label>
<div class="controls">
<input type="file" name="userfile" />
</div>
</div>
<div class="control-group">
<label class="control-label"><?php echo get_phrase('description');?></label>
<div class="controls">
<textarea name="description" ></textarea>
</div>
</div>
<div class="control-group">
<div class="controls">
<input type="hidden" name="prescription_id" value="<?php echo $prescription_id;?>" />
<button type="submit" class="btn btn-blue"><?php echo get_phrase('add_diagnosis_report');?></button>
</div>
</div>
</div>
</form>
</div>
</div>
这是我在数据库中上传文件的代码:
function manage_prescription($param1 = '', $param2 = '', $param3 = '')
{
if ($this->session->userdata('laboratorist_login') != 1)
redirect(base_url() . 'index.php?login', 'refresh');
if ($param1 == 'create_diagnosis_report') {
$data['report_type'] = $this->input->post('report_type');
$data['document_type'] = $this->input->post('document_type');
$data['prescription_id'] = $this->input->post('prescription_id');
$data['description'] = $this->input->post('description');
$data['timestamp'] = strtotime(date('Y-m-d') . ' ' . date('H:i:s'));
$data['laboratorist_id'] = $this->session->userdata('laboratorist_id');
move_uploaded_file($_FILES["userfile"]["tmp_name"] , "uploads/diagnosis_report/".$_FILES["userfile"]["name"]);
$data['file_name'] = $_FILES["userfile"]["name"];
$this->db->insert('diagnosis_report', $data);
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_created'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $this->input->post('prescription_id'), 'refresh');
}
if ($param1 == 'delete_diagnosis_report') {
$this->db->where('diagnosis_report_id', $param2);
$this->db->delete('diagnosis_report');
$this->session->set_flashdata('flash_message', get_phrase('diagnosis_report_deleted'));
redirect(base_url() . 'index.php?laboratorist/manage_prescription/edit/' . $param3, 'refresh');
} else if ($param1 == 'edit') {
$page_data['edit_profile'] = $this->db->get_where('prescription', array(
'prescription_id' => $param2
))->result_array();
}
$page_data['page_name'] = 'manage_prescription';
$page_data['page_title'] = get_phrase('manage_prescription');
$page_data['prescriptions'] = $this->db->get('prescription')->result_array();
$this->load->view('index', $page_data);
}
答案 0 :(得分:1)
您必须在视图文件中使用form_open_multipart()
而不是form_open()