请帮助我将用户1的图像更新为abc.jpg然后如果我更新用户2的爱好,那么它的个人资料pic被用户1图像替换不知道为什么?
public function multiple_image_upload()
{
$config = array();
$config['upload_path'] = './uploads/user_avatars/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$config['max_width'] = 10240;
$config['max_height'] = 7680;
$images = array();
$count = (count($_FILES['avatar']['name'])>0);
if($_FILES['avatar']['name']!= Null && ($count = count($_FILES['avatar']['name'])) > 0)
//using this its working fine but my images are overlapped
{
$files = $_FILES;
$images = array();
/* check if folder with year exists*/
$current_year = date('Y');
$path = './uploads/user_avatars/'.$current_year;
if(is_dir($path)){
/* do nothing */
}else{
/* create directory */
@mkdir( $path , 0755, true );
}
$images = array();
for($i = 0; $i < @$count; $i++)
{
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '100000';
$config['max_width'] = '102400';
$config['max_height'] = '76800';
$this->load->library('upload', $config);
if ($this->upload->do_upload('avatar'))
{
$data = $this->upload->data();
/* create thumbnail */
$this->load->helper('image_thumb_helper');
generate_image_thumb($data['full_path'],$path,$data['file_name']);
/* add to database */
$images[$i]['file_name'] = $current_year.'/'.$data['file_name'];
$images[$i]['thumb'] = $current_year.'/thumb_'.$data['file_name'];
}else{
$this->form_validation->set_message('multiple_image_upload',$this->upload->display_errors());
return false;
}
}
$this->session->set_userdata('uploaded_images',$images);
return true;
}
else{
return true;
}
}
以上是我需要帮助解决此问题的代码
if($_FILES['avatar']['name']!= Null && ($count = count($_FILES['avatar']['name'])) > 0)
主要问题在于我猜,但不确定
答案 0 :(得分:1)
首先,检查$ count变量的计数。然后保持在下面 如果($ _ FILES ['avatar'] ['name']!= NULL&amp;&amp; count($ _ FILES ['avatar'] ['name'])&gt; 0)
我不知道你为什么要使用for循环?如果它们只是一个图像,则$ i将为0.因此,它总是被第一个替换。