CodeIgniter将一个图像上传到两个目录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeIgniter将一个图像上传到两个目录相关的知识,希望对你有一定的参考价值。

我想将一个图像上传到CodeIgniter中的不同目录,因此一个图像存储在2个文件夹中。

路径一等/ www / image1 /和路径二等/ www / image2 /

$config[‘upload_path’] =‘etc/www/image1/’;
$config[‘allowed_types’] = ‘jpg|jpeg|gif|png’;
$config[‘file_name’]=“imageone.jpg”;
$config[‘max_size’] = ‘10000’;

$this->upload->initialize($config); 
if(!$this->upload->do_upload(‘userfile’)){
echo $this->upload->display_errors();
}else {
$this->upload->data(‘userfile’);
} 
答案

在CI控制器方法中成功上传文件后,只需使用phpCopy()函数即可...

EX:

$file = '/www/image1/example.txt';
$newfile = '/www/image1/example.txt';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
另一答案
 $config['upload_path'] = FCPATH.'upload/';
    $config['allowed_types'] = FCPATH.'gif|jpg|jpeg|png';
    $config['encrypt_name'] = TRUE;
    $this->load->library('upload',$config);
    $upload = $this->upload->do_upload("resim");
    if($upload){
        $resim = $this->upload->data();
        $resimadi = $resim['file_name'];
        $resimkayit = 'upload/'.$resimyolu.'';
        $resimhotnews = 'upload/hotnews'.$resimadi.'';
        $resimlastnews = 'upload/lastnews'.$resimadi.'';
        $config['image_library'] = 'gd2';
        $config['source_image'] = 'upload/'.$resimadi.'';
        $config['new_image'] = 'upload/hotnews'.$resimadi.'';
        $config['create_thumb'] = FALSE;
        $config['maintain_ratio'] = FALSE;
        $config['quality'] = '%80';
        $config['width'] = 500;
        $config['height'] = 350;

        $this->load->library('image_lib', $config);
        $this->image_lib->initialize($config);
        $this->image_lib->resize();
        $this->image_lib->clear();
        //tmb folder resim uploading end

//迷你文件夹图片上传开始

        $config1['image_library'] = 'gd2';
        $config1['source_image'] = 'upload/'.$resimadi.'';
        $config1['new_image'] = 'upload/lastnews/'.$resimadi.'';
        $config1['create_thumb'] = FALSE;
        $config1['maintain_ratio'] = FALSE;
        $config1['quality'] = '%80';
        $config1['width'] = 200;
        $config1['height'] = 150;

        $this->load->library('image_lib', $config1);
        $this->image_lib->initialize($config1);
        $this->image_lib->resize();
        $this->image_lib->clear();

//在mac计算机上,你必须为文件夹提供可写权限

以上是关于CodeIgniter将一个图像上传到两个目录的主要内容,如果未能解决你的问题,请参考以下文章

使用 CodeIgniter 将上传图像字段添加到注册表单

带有 Summernote 的 CodeIgniter - 无法将图像上传到数据库

如何将图像路径和名称上传到数据库 - Codeigniter

无法将变量从控制器传递到模型以处理codeigniter中的多个上载字段

如何将文件图像存储到 mysql (Codeigniter)

codeigniter 文件上传 - 可选?