我有一个包含3个字段的表单。
所有3个字段都是必填字段,并具有验证规则。
当我提交表单时,我可以使用set_value();
如何设置图像的提交值?
如果我再次提交表格,请让我再次上传图片。
post_plot(查看)
<form method ="post" enctype="multipart/form-data">
<div>
<label>Property Title</label>
<input type="text" name="title" value="<?php echo set_value('Title'); ?>" />
</div>
<div>
<label>Property type</label>
<input type="text" name="type" value="<?php echo set_value('type'); ?>" />
</div>
<div>
<label>File</label>
<input type="file" name="img" value="<?php echo set_value('img'); ?>" />
</div>
<div>
<input type="submit" name="submit" value="submit" />
</div>
</form>
绘图控制器
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Plot extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('Admin_layout');
$this->load->model('admin/plot_model');
$this->config->load('plot_rules');
$this->output->enable_profiler(TRUE);
$this->new_name='';
}
public function index()
{
if (!$this->auth->loggedin()) {
redirect('admin/login');
}
}
public function add(){
$this->form_validation->set_rules($this->config->item('plot_settings'));
$this->form_validation->set_error_delimiters('<p><b>', '</b></p>');
$data["plot_attrib"] = $this->config->item("plot_attribute");
$data["plot_attrib"]['title'] = 'Add Plot';
$data["plot_attrib"]['action'] = base_url('admin/plot/add');
$location = $this->plot_model->get_location();
$property_type = $this->plot_model->get_property_type();
$data["plot_attrib"]['location_dropdown'] = $location;
$data["plot_attrib"]['property_dropdown'] = $property_type;
$data["plot_attrib"]["error"] = ' ' ;
$add_attributes = $data["plot_attrib"];
// echo '<pre>'; print_r($add_attributes); echo '</pre>';
if ($this->form_validation->run('submit') == FALSE )
{
$this->admin_layout->set_title('Post Plot');
$this->admin_layout->view('admin/post_plot',$add_attributes);
}
else {
$img = "img";
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->new_name = 'plot_'.round(microtime(true));
$config['file_name'] = $this->new_name;
$this->load->library('upload', $config);
if($this->upload->do_upload('img')){
$data = array('upload_data' => $this->upload->data());
//echo '<pre>'; print_r($data); echo '</pre>';
$config['image_library'] = 'gd2';
$config['source_image'] = $data['upload_data']['full_path'];
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 500;
$config['height'] = 500;
$this->load->library('image_lib', $config);
$this->image_lib->resize();
$config['source_image'] = $data['upload_data']['full_path'];
$config['wm_text'] = 'Copyright Feroz Akbar :P';
$config['wm_type'] = 'text';
//$config['wm_font_path'] = './system/fonts/texb.ttf';
$config['wm_font_size'] = '10';
$config['wm_font_color'] = 'ffffff';
$config['wm_vrt_alignment'] = 'bottom';
$config['wm_hor_alignment'] = 'center';
$config['wm_padding'] = '5';
$this->image_lib->initialize($config);
$this->image_lib->watermark();
$this->new_name = $data['upload_data']['orig_name'];
$this->admin_layout->view('admin/post_plot',$add_attributes);
$this->insert();
}else{
$error = $this->upload->display_errors();
$add_attributes['error'] = $error;
$this->admin_layout->view('admin/post_plot',$add_attributes);
}
}
}//add
}