2016-04-07 14 views
3

2 resim ayrı ayrı yüklemek istiyorum. Ben dosya ve bazı zaman bohth ve bir zaman sadece görüntü yüklemeniz gereken bir koşul var her iki görüntü ve dosya ayırt etmek için ayrı bir düğme kullanmak gerekir.2 ayrı resmi nasıl yükleyebilirim?

benim kodları onlara farklı isimler vermek gerekir, 2 farklı dosya düğmesini istiyorsanız bu kontrolör

function ddoo_upload(){ 
    $config['upload_path'] = './uploads/'; 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size'] = '100'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768'; 

    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload()) { 
     $error = array('error' => $this->upload->display_errors()); 
     $this->load->view('upload_form', $error); 
    } else { 
     $data = array('upload_data' => $this->upload->data()); 
     $this->load->view('upload_success', $data); 
    } 
} 
+0

Sadece bir dosya yükleme düğmesini kullanabilir ve bu düğmeye "çoklu =" çoklu "' özniteliğini ekleyebilir ve sunucu tarafındaki dosya türü arasında ayrım yapabilirsiniz. – sahil

+0

no Müşterimiz –

+0

'un gereksinimi olan iki düğüme gerek yok Bu [cevap] 'a bakabilirsiniz (http://stackoverflow.com/a/4237161/3863146) ve dosya türüne göre yükleme yapabilirsiniz. – sahil

cevap

0

olduğunu

<form action="http://localhost/cod_login/club/test2" enctype="multipart/form-data" method="post" accept-charset="utf-8"> 
    <input type="file" name="userfile" size="20"> 
    <input type="file" name="userfile" size="20"> 
    <input type="submit" name="submit" value="upload"> 
</form> 

bulunmaktadır. Farklı dosya yüklemek için kullanarak daha değişken olarak $ dosya geçiyoruz ve: Eğer

function ddoo_upload($filename){ 
$config['upload_path'] = './uploads/'; 
$config['allowed_types'] = 'gif|jpg|png'; 
$config['max_size'] = '100'; 
$config['max_width'] = '1024'; 
$config['max_height'] = '768'; 

$this->load->library('upload', $config); 
if (! $this->upload->do_upload($filename)) { 
    $error = array('error' => $this->upload->display_errors()); 
return false; 
// $this->load->view('upload_form', $error); 
} else { 
$data = array('upload_data' => $this->upload->data()); 
return true; 
//$this->load->view('upload_success', $data); 
} 

}

NOT aşağıda gibi işlev ddoo_upload değiştirmek zorunda Daha

<form action="" enctype="multipart/form-data" method="post" accept-charset="utf-8"> 
<input type="file" name="userfile1" size="20"> 
<input type="file" name="userfile2" size="20"> 
<input type="submit" name="submit" value="upload"> 

.

Artık form eyleminin yönlendirildiği denetleyicide, aşağıdaki kodu yazmanız gerekir.

if ($this->input->post('submit')){ 
if (isset($_FILES['userfile1']) && $_FILES['userfile1']['name'] != ''){ 
    $file1 = $this->ddoo_upload('userfile1'); 
} 

if (isset($_FILES['userfile2']) && $_FILES['userfile2']['name'] != ''){ 
    $file2 = $this->ddoo_upload('userfile2'); 
} 

}

0
<form action="http://localhost/cod_login/club/test2" enctype="multipart/form-data" method="post" accept-charset="utf-8"> 


<input type="file" name="userfile" size="20" multiple=""> 
<input type="submit" name="submit" value="upload"> 
</form> 
+0

efendim, bir –

+0

numaralı iki düğüme ihtiyacım var ve tek bir düğmede –

+0

görüntülerini ayrı ayrı yüklemeniz gerekiyor, tek bir görüntüyü ve diğer çoklu görüntüyü yüklemeniz gerekecek. –

0

Bu şimdiye CodeIgniter'daki

halka fonksiyon indeksi() {

if($this->input->post('Submit')){ 

//-----------Image File Section Start Here -----------// 

$config['upload_path'] = './uploads/'; // Directory 
$config['allowed_types'] = 'jpg|jpeg|bmp|png'; //type of images allowed 
$config['max_size'] = '30720'; //Max Size 
$config['encrypt_name'] = TRUE; // For unique image name at a time 

$this->load->library('upload', $config); //File Uploading library 
$this->upload->do_upload('userfile'); // input name which have to upload 
$video_upload=$this->upload->data(); //variable which store the path 

//--------------End of Image File Section------------------------// 



//---------Thumbnail Image Upload Section Start Here -----------// 

$config2['upload_path'] = './thumb/'; // Directory 
$config2['allowed_types'] = 'jpg|jpeg|bmp|png'; //type of images allowed 
$config2['max_size'] = '30720'; //Max Size 
$config2['encrypt_name'] = TRUE; // For unique image name at a time 


$this->upload->initialize($config2); //we can not use upload library again and again it will not initialize again and again so thats why i have used initialize 
$this->upload->do_upload('txt_thumb'); // File Name 
$thumbnail_upload=$this->upload->data(); // store the name of the file 

//--------End of Thumbnail Upload Section-----------// 



    $date=date("d-m-Y"); // Store current date in variable 

    // Here the database query to insert 

    $data = array(
    'parent_id'=> $this->input->post('txt_parent'), 
    'cat_id' => $this->input->post('txt_category'), 
    'title'=> $this->input->post('txt_title'), 
    'status' => $this->input->post('txt_status'), 
    'featured' => $thumbnail_upload['file_name'], 
    'image' => $video_upload['file_name'], 
    'time'=>$date 
    ); 

     $sql_ins= $this->Insimage->insertimage($data); 
     if($sql_ins) 
     { 
      $data['Success'] = "Image has been succesfully inserted!!"; 
     } 

}

Bu iki resim yükleyerek başvurusunda kontrol kodu kod kesinlikle 2 görüntüyü yüklemek için çalışacaktır Keyfini çıkarın !!!! :-)

İlgili konular