php Codeigniter上传图像和视频到不同的文件夹

qv7cva1a  于 2023-06-04  发布在  PHP
关注(0)|答案(1)|浏览(204)

图像上传成功,但视频未上传,encrypt_name在视频文件名处不起作用请帮助解决此问题。
这是我的控制器:

$image = $_FILES['imagearchiev']['tmp_name'];
$video = $_FILES['videoarchiev']['tmp_name'];
            
if ($image !== NULL && $video !== NULL) {
    if ($image) {           
        $config['upload_path'] = realpath('assets/image/icon/');
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = 2000; 
        $config['encrypt_name'] = true;
        $this->load->library('upload', $config);
        $this->upload->do_upload('imagearchiev');
        $data_upload = $this->upload->data(); 
        $imagearchiev = $data_upload['file_name'];
    }

    if ($video) {                    
        $config2['upload_path'] = realpath('assets/image/icon/');
        $config2['allowed_types'] = 'mp4|MP4';
        $config2['max_size'] = 20000000;
        $config2['encrypt_name'] = true;
        $this->load->library('upload', $config2);
        $this->upload->do_upload('videoarchiev');
        $data_upload2 = $this->upload->data(); 
        $videoarchiev = $data_upload2['file_name'];
    }

    $titlearchiev = $this->input->post('titlearchiev');
    $textarchiev = $this->input->post('summernote');
    redirect('admin/addarchievement');
}
n3schb8v

n3schb8v1#

根据所需的文件夹结构修改路径

$image = $_FILES['imagearchiev']['tmp_name'];
$video = $_FILES['videoarchiev']['tmp_name'];

if (!empty($image) && !empty($video)) {
    if ($image) {           
        $config['upload_path'] = './assets/image/icon/';
        $config['allowed_types'] = 'gif|jpg|png|jpeg';
        $config['max_size'] = 2000; 
        $config['encrypt_name'] = true;

        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        $this->upload->do_upload('imagearchiev');
        $data_upload = $this->upload->data(); 
        $imagearchiev = $data_upload['file_name'];
    }

    if ($video) {                    
        $config2['upload_path'] = './assets/video/';
        $config2['allowed_types'] = 'mp4|MP4';
        $config2['max_size'] = 20000000;
        $config2['encrypt_name'] = true;

        $this->load->library('upload', $config2);
        $this->upload->initialize($config2);
        $this->upload->do_upload('videoarchiev');
        $data_upload2 = $this->upload->data(); 
        $videoarchiev = $data_upload2['file_name'];
    }

    $titlearchiev = $this->input->post('titlearchiev');
    $textarchiev = $this->input->post('summernote');
    redirect('admin/addarchievement');
}

相关问题