我在这里讨论着如何p中上传多个图像总MVC模式HP
public function finishing_product()
{
if($this->session->userdata('user_name') == TRUE)
{
$data['user_name']=$this->session->userdata('user_name');
//$this->load->library('upload'$config);
if(isset($_POST['sub1']))
{
$this->load->model('student_reg');
$data['cat_id']=$_POST['cat_id'];
if ($data['cat_id']=="1")
{
$loc='C:/xampp/htdocs/mahata/uploads/';
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++)
{
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$this->load->library('upload', $config);
$this->upload->initialize($this->set_upload_options());
$this->upload->do_upload();
$name = $_FILES["userfile"]["name"][$i];
$ext = end((explode(".", $files['userfile']['name'][$i])));
echo $file;
$id=$this->student_reg->finishing_cat1($data);
$file= $id.".".$ext;
$filepath= $loc . $file;
echo $filepath;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $filepath))
{
echo "File is valid, and was successfully uploaded.\n";
}
else {
echo "Upload failed";
}
}
}
$this->load->view('finishing_product',$data);
}
else
{
redirect("index");
}
}
我的模型
public function infra_cat1($data)
{
$sql="INSERT INTO `infracat1`(`category_id`)
VALUES (".$data['cat_id'].")";
$this->db->query($sql);
$id=$this->db->insert_id();
return $id;
}
我查看文件
<div class="col-lg-5">
<div class="form-group required"> <label class="control-label">Infra Category</label>
<select name="cat_id" class="form-control" >
<option value="-1">select</option>
<option value="1" <?php if ($month_b==1) {echo "selected";}?> >Steel </option>
<option value="2" <?php if ($month_b==2) {echo "selected";}?> >Electrical</option>
<option value="3" <?php if ($month_b==3) {echo "selected";}?> >Plumbing solution</option>
<option value="4" <?php if ($month_b==4) {echo "selected";}?> >Water Proofing</option>
<option value="5" <?php if ($month_b==5) {echo "selected";}?> >Manufactured and Plastering Sand</option>
<option value="6" <?php if ($month_b==6) {echo "selected";}?> >Pavers</option>
<option value="7" <?php if ($month_b==7) {echo "selected";}?> >Windows </option>
</select>
<div>
<table class="table table-stripped">
<tbody>
<tr>
<td>Display</td>
<td>
<input class="form-control" type="file" name="userfile[]" id="multiple" multiple="" />
</td>
</tr>
<tr>
<td colspan="2">
<button type="submit" name="sub1" class="btn btn-primary btn-outline btn-block pull-right"><span>Save</span></button>
</td>
</tr>
</tbody>
谢谢你工作得很好..... –
你WELCO我 :) –