-1
我有一個窗體可以編輯數據庫中的幾個字段,並且我有一個字段可以上傳照片。所有文本字段在數據庫中更新,除了圖像字段,照片名稱始終爲空,我不知道爲什麼!該參數始終爲空:$ profile_img。任何人都可以幫助我。我正在使用CodeIgniter。感謝 這是我的控制器:照片名稱字段始終爲空
function superadmin_landing_content_edit() {
$content_id = $this->uri->segment(4);
if (empty($_FILES['content_img']['name']))
{
$this->form_validation->set_rules('content_img', 'Image', 'required');
}
if (isset($_POST) && !empty($_POST))
{
if(isset($_FILES["content_img"]["name"]) and !empty($_FILES["content_img"]["name"])) {
$config['upload_path'] = $this->config->config["public_path"]."landing/";
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '20000000';
$config['max_width'] = '2024';
$config['max_height'] = '2024';
$this->load->library('upload');
$this->upload->initialize($config);
$result = $this->upload->do_upload('content_img');
if($result>=1) {
$imageinfo = $this->upload->data();
$profile_img = $imageinfo["file_name"];
$profile_img = $profile_img."*".'/var/www/html/upload/home/landing/'.$profile_img; //always null
}
}
$data = array(
'name' => $this->input->post('name'),
'image_link' => $profile_img, //here always null
'type' => $this->input->post('type'),
'link' => $this->input->post('link'),
'property_type_id' => $this->input->post('prop_id'),
'orientation_id' => $this->input->post('ori_id'),
'state_id' => $this->input->post('state'),
'city_id' => $this->input->post('city'),
'flag' => $this->input->post('flag'),
);
if ($this->form_validation->run() === true)
{
$this->Admin_model->update_landing_content($content_id, $data);
}
}
$this->load->view('admin/superadmin_landing_content_edit', $data);
}
這裏是我的看法:
<?php $content_id = $content['id']; ?>
<?php $attributes = array("name" => "content_img_edit", "id" => "content_img_edit", "class" => "edit_view","method" => "post");
echo form_open_multipart("admin/admin/superadmin_landing_content_edit/".$content_id, $attributes); ?>
<div class="form-group">
<label>Image</label>
<?php echo form_upload(array("id"=>"content_img", "name"=>"content_img", "class"=>"form-control"))?>
</div>
<div class="form-group">
<?php echo form_submit('submit', 'Submit', 'class="btn btn-default"');?>
<input type="button" name="btnBack" class="btn btn-default" id="btnBack" value="Landing Content List" onclick="window.location.href='<?php echo base_url() ?>admin/admin/superadmin_landing_content_list'" />
</div>
<?php echo form_close(); ?>
請刪除所有與您的問題無關的代碼。 – OptimusCrime
我編輯了我的代碼.. –
你在$ imageinfo中獲得了什麼?也$ this-> load-> library('upload');在那兒? –