コントローラークラスコードが次のようになるように、コードイグナイターフレームワークを使用して画像をアップロードしようとしています
public function addNewSlider()
{
if($this->session->userdata('logged_in'))
{
$this->form_validation->set_rules('title','Title','required');
if($this->form_validation->run()===FALSE)
{
$data['content']=$this->input->get_post('content');
$data['file']=$this->input->get_post('file');
$data['status']=$this->input->get_post('status');
$this->load->view('admin/templates/header',array('sessionArray'=>$this->sessionArray));
$this->load->view('admin/sliders/addNewSlider',$data);
$this->load->view('admin/templates/footer');
}
else
{
/*$title=$this->input->get_post('title');
$content=$this->input->get_post('content');
$image=$this->input->get_post('file');
$status=$this->input->get_post('status');
$this->sliders_model->insertNewMenu($title,$content,$image,$status);
redirect('sliders','refresh');*/
}
}
else
{
redirect('index','refresh');
}
}
function do_upload()
{
$name=time();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
// $config['max_size'] = '100';
// $config['max_width'] = '1024';
//$config['max_height'] = '768';
$config['file_name']=$name;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
print_r($error);exit;
//$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
//$this->load->view('upload_success', $data);
}
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$name.'.jpg';
$config['new_image'] = './uploads/'.$name.'.jpg';
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 1000;
$config['height'] = 400;
$this->image_lib->resize();
$config['new_image'] = './uploads/'.$name.'.jpg';
$config['width'] = 1000;
$config['height'] = 400;
$this->image_lib->initialize($config);
$this->image_lib->resize();
$title=$this->input->get_post('title');
$content=$this->input->get_post('content');
$image=$name.'.jpg';
$status=$this->input->get_post('status');
$this->sliders_model->insertNewSlider($title,$content,$image,$status);
redirect('sliders','refresh');
}
**and my view file is code is as follows**
<?php echo form_open_multipart('sliders/do_upload',array('class'=>'search_form general_form'));?>
<!--[if !IE]>start fieldset<![endif]-->
<fieldset>
<!--[if !IE]>start forms<![endif]-->
<div class="forms">
<!--[if !IE]>start row<![endif]-->
<div class="row">
<label>Title:</label>
<div class="inputs">
<span class="input_wrapper"><input class="text" name="title" id="title" type="text" value="<?php //echo $title?>"/>
</span>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
<!--[if !IE]>start row<![endif]-->
<div class="row">
<label>Image Path:</label>
<div class="inputs">
<!--<input type="file" name="file" id="file" /> -->
<input type="file" name="file"/>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
<!--[if !IE]>start row<![endif]-->
<div class="row">
<label>Content:</label>
<span class="input_wrapper textarea_wrapper">
<textarea rows="5" cols="5" class="text" name="content"><?php //echo $content?></textarea>
</span>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
<!--[if !IE]>start row<![endif]-->
<div class="row">
<label>Status:</label>
<div class="inputs">
<span class="input_wrapper blank">
<select name="status">
<?php if(isset($_POST['status']))
{
$one='1';
$zero='0';
if($_POST['status']==$one)
{ echo "InIF";?>
<option value="1" selected="selected" >Active</option>
<option value="0" >Inactive</option>
<?php }else if($_POST['status']==$zero){echo "InElseIF";?>
<option value="0" selected="selected" >Inactive</option>
<option value="1">Active</option>
<?php }
}
else
{
echo "InElse"; ?>
<option value="1" >Active</option>
<option value="0" >Inactive</option>
<?php }?>
</select>
</span>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
<!--[if !IE]>start row<![endif]-->
<div class="row">
<div class="buttons">
<ul>
<li><span class="button send_form_btn"><span><span>SEND FORM</span></span><input value="upload" type="submit" /></span></li>
<li><a href="<?php echo base_url()?>sliderTable.php" class="button uncheck_all"><span><span>Cancel</span></span></a></li>
</ul>
</div>
</div>
<!--[if !IE]>end row<![endif]-->
</div>
<!--[if !IE]>end forms<![endif]-->
</fieldset>
<!--[if !IE]>end fieldset<![endif]-->
</form>
私の主な問題は、送信ボタンを押しているときに、アップロードするファイルが選択されていないというエラー メッセージが表示されることです。が表示されます。この問題をすぐに克服するのを手伝ってくれる人はいますか?