当我尝试上传图片时,根本不上传,我的代码就在这里
public function image_upload($path)
{
if($_FILES)
{
$config['upload_path'] = './uploads/'.$path.'/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '4000';
$config['max_height'] = '6500';
$config['file_name'] ='img';
$this->load->library('upload', $config);
if(! $this->upload->do_upload("file"))
{
$this->session->set_flashdata('message',$this->upload->display_errors());
return false;
}
else
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$path.'/'.$this->upload->file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 200;
$config['height'] = 150;
$config['new_image'] = './uploads/'.$path.'/thumb/';
$this->load->library('image_lib',$config);
if(! $this->image_lib->resize())
{
$this->session->set_flashdata('message',$this->image_lib->display_errors());
return false;
}
else
{
return $this->upload->file_name;
}
}
}
}
我的观看页面是这个
<form role="form" action="<?php echo base_url();?>admin/add_staff" method="post" enctype="multipart/form-data">
<tr>
<td>Photo</td>
<td><input type="file" id="file" name="file"></td>
</tr>
<tr>
<td></td>
<td> <input class="btn btn-primary save-btn" type="submit" value="Save" > </td>
</tr>
</form>
我的cntroller看起来像这样
public function add_staff()
{
$data['active_mn'] = 'add_staff';
if($_POST)
{
$this->form_validation->set_rules('name', 'Name', 'required');
if($this->form_validation->run() == true)
{
if( ! $this->image_upload($path = 'staff') )
{
$photo = '';
}
else
{
$photo = $this->upload->file_name;
}
$data = array('photo'=>$photo);
$status = $this->admin_model->db_insert($table='staff',$data);
if($status)
{
$this->session->set_flashdata('message','Staff added Successfully');
}
else
{
$this->session->set_flashdata('message','Insertion failed');
}
redirect('admin/view_staff');
}
}
$this->load->view('admin/add_staff',$data);
}
我已经通过多种方式但没有得到解决方案。这会是系统文件问题吗?
答案 0 :(得分:0)
以下是我上传多张图片的代码
CloudKit
这是视图部分
if(isset($_GET['did']))
{
$id = $_GET['did'];
$part = "img/";
$img = mysql_query("SELECT * FROM tbproduct_detail WHERE p_id = '$id'");
while($r = mysql_fetch_object($img))
{
$old = $r->profile;
unlink($part.$old);
}
mysql_query("DELETE FROM tbproduct_detail WHERE p_id = '$id'");
mysql_query("DELETE FROM tbproduct WHERE id = '$id'");
}
if(isset($_POST['upload']))
{
$product_name = $_POST['product_name'];
mysql_query("INSERT INTO tbproduct(product_name) VALUES('$product_name')");
$id = mysql_insert_id();
if($id > 0)
{
foreach($_FILES['file']['tmp_name'] as $i => $tmp_name)
{
$filename = $_FILES['file']['name'][$i];
$filetype = $_FILES['file']['type'][$i];
$filesize = $_FILES['file']['size'][$i];
$filetmp = $_FILES['file']['tmp_name'][$i];
$store = rand(0,13248575858).$_FILES['file']['name'][$i];
if(move_uploaded_file($filetmp,"img/".$store))
{
mysql_query("INSERT INTO tbproduct_detail(p_id,file_name,file_size,file_ext,profile) VALUES('$id','$filename','$filesize','$filetype','$store')");
}
}
}
}?>
这是sql
<form action="" method="post" enctype="multipart/form-data">
<table class="table">
<tr>
<td>
<label>ProductName</label>
<input type="text" name="product_name" class="form-control">
</td>
</tr>
<tr>
<td>
<label>Profile</label>
<input type="file" name="file[]" multiple class="form-control">
</div>
</td>
</tr>
<tr>
<td>
<label>ProductName</label>
<input type="text" name="product_name" class="form-control">
</td>
</tr>
<tr>
<td>
<label>Profile</label>
<input type="file" name="file[]" multiple class="form-control">
</div>
</td>
</tr>
<input type="submit" value="upload" class="btn btn-primary" name="upload">
</table>
</form>
&#13;