Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 无法在codeigniter中设置新图像名称_Image_Codeigniter_Model View Controller_Codeigniter 3_Codeigniter 2 - Fatal编程技术网

Image 无法在codeigniter中设置新图像名称

Image 无法在codeigniter中设置新图像名称,image,codeigniter,model-view-controller,codeigniter-3,codeigniter-2,Image,Codeigniter,Model View Controller,Codeigniter 3,Codeigniter 2,我正在codeigniter中上载多个图像,但当我使用此代码设置新名称时,$\u FILES['attachment']['name']=$filename 我越来越 不允许您尝试上载的文件类型 请建议解决此问题的解决方案。 public function do_upload() { if (($_SERVER['REQUEST_METHOD']) == "POST") { $count = count($_FILES['attach_file']['

我正在codeigniter中上载多个图像,但当我使用此代码设置新名称时,
$\u FILES['attachment']['name']=$filename

我越来越

不允许您尝试上载的文件类型

请建议解决此问题的解决方案。

public function do_upload()
{
    if (($_SERVER['REQUEST_METHOD']) == "POST") {
        $count = count($_FILES['attach_file']['name']);
        $files = $_FILES;
        for($i=0; $i<$count; $i++){
        $filename = $_FILES['attach_file']['name'][$i];
        $filename = strstr($filename, '.', true);
        $email    = $this->session->userdata('email');
        $filename = strstr($email, '@', true)."_".$filename;
        $filename = strtolower($filename);

        $_FILES['attachment']['name']= $filename;
        $_FILES['attachment']['type']= $_FILES['attach_file']['type'][$i];
        $_FILES['attachment']['tmp_name']= $_FILES['attach_file']['tmp_name'][$i];
        $_FILES['attachment']['error']= $_FILES['attach_file']['error'][$i];
        $_FILES['attachment']['size']= $_FILES['attach_file']['size'][$i];    
        $config['upload_path']   = FCPATH .'./assets/attachments/new/';
        $config['allowed_types'] = 'pdf|doc|docx|bmp|gif|jpg|jpeg|jpe|png';
        $config['max_size']      = 0;
        $config['max_width']     = 0;
        $config['max_height']    = 0;
        $config['encrypt_name']  = true; 
        $config['file_ext_tolower'] = true; 
        $config['overwrite']     = false;
        $this->load->library('upload', $config);
        if (!$this->upload->do_upload('attachment')) {
            $data['exception'] = $this->upload->display_errors();
            $data['status'] = false;
            echo json_encode($data);
        } else {
            $upload =  $this->upload->data();
            $data['message'] = 'upload_successfully';
            $data['filepath'] = './assets/attachments/'.$upload['file_name'];
            $data['status'] = true;
            echo json_encode($data);
        }
    }  
    }
}
public函数do_upload()
{
如果($_服务器['REQUEST\u METHOD'])==“POST”){
$count=count($_文件['attach_文件]['name']);
$files=$\u文件;
对于($i=0;$i会话->用户数据('email');
$filename=strstrstr($email,'@',true)。“..$filename;
$filename=strtolower($filename);
$\u文件['attachment']['name']=$filename;
$\u文件['attachment']['type']=$\u文件['attachment\u文件]['type'][$i];
$\u文件['attachment']['tmp\u name']=$\u文件['attache\u file']['tmp\u name'][$i];
$\u文件['attachment']['error']=$\u文件['attache\u file']['error'][$i];
$\u文件['attachment']['size']=$\u文件['attachment\u文件]['size'][$i];
$config['upload_path']=FCPATH./assets/attachments/new/”;
$config['allowed_types']=“pdf | doc | docx | bmp | gif | jpg | jpeg | jpe | png”;
$config['max_size']=0;
$config['max_width']=0;
$config['max_height']=0;
$config['encrypt_name']=true;
$config['file\u ext\u tolower']=true;
$config['overwrite']=false;
$this->load->library('upload',$config);
如果(!$this->upload->do_upload('attachment')){
$data['exception']=$this->upload->display_errors();
$data['status']=false;
echo json_编码($data);
}否则{
$upload=$this->upload->data();
$data['message']='upload_successfully';
$data['filepath']='./资产/附件/'.$upload['file_name'];
$data['status']=true;
echo json_编码($data);
}
}  
}
}

注意:-您将再次分配相同的变量名&再次
$filename

请更改此:-

$filename = $_FILES['attach_file']['name'][$i];
$filename = strstr($filename, '.', true);
$email    = $this->session->userdata('email');
$filename = strstr($email, '@', true)."_".$filename;
$filename = strtolower($filename);

$_FILES['attachment']['name']= $filename;
$filename = $_FILES['attach_file']['name'][$i];
$filename1 = strstr($filename, '.', true);
$email    = $this->session->userdata('email');
$filename2 = strstr($email, '@', true)."_".$filename1;
$filename3 = strtolower($filename2);  
至:-

$filename = $_FILES['attach_file']['name'][$i];
$filename = strstr($filename, '.', true);
$email    = $this->session->userdata('email');
$filename = strstr($email, '@', true)."_".$filename;
$filename = strtolower($filename);

$_FILES['attachment']['name']= $filename;
$filename = $_FILES['attach_file']['name'][$i];
$filename1 = strstr($filename, '.', true);
$email    = $this->session->userdata('email');
$filename2 = strstr($email, '@', true)."_".$filename1;
$filename3 = strtolower($filename2);  

您正在上载哪种文件类型???@KUMAR:我正在上载jpeg类型文件请删除
$config['max\u size']=0;
$config['max\u width']=0;
$config['max\u height']=0;
&让我知道。您使用的是哪一个版本:CI 2.x还是3.x?@KUMAR:删除了代码,但出现了相同的错误尝试了上述代码,但在我提取$config[“allowed_types”]=“*”时出现了相同的问题;然后上传一个普通文件,不带任何extension@user3653474上传的文件名是否在“是否更改”文件夹中???@KUMAR-不,它不会更改图像文件name@user3653474您想在插入之前更改上传的图像名和表插入名???@user3653474只需echo
$filename3=strtolower($filename2);
它返回的文件名相同还是不同??