0

我想将一张图片上传到 CodeIgniter 中的不同目录,所以一张图片存储在 2 个文件夹中。

路径一 etc/www/image1/ 和路径二 etc/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’);
} 
4

2 回答 2

2

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

前任:

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

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
于 2012-09-03T07:51:46.423 回答
0
 $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

//迷你文件夹resim上传开始

        $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电脑上,你必须给文件夹一个可写的权限

于 2018-05-19T19:30:43.003 回答