2014-02-03 3 views
-1

У меня проблема при загрузке нескольких изображений, я могу загружать только одно изображение, и когда я выбираю следующий образ, предыдущее изображение теряется.Как загрузить несколько изображений в cakephp?

Мой вид страницы, как это:

<div id="for_image0" class="inline-form" style="display:none;"> 
    <span> 
     <input type='file' name="data[ReportManagement][imageUploader]" id="file_upload" onchange="readURL(this);" /> 
     <span id="extension_error" style="color:red;"></span> 
     <br/> 
    </span>   
    <span id="previewPane"> 
     <img style="width:150px;float:left;" id="img_prev" src="#" /> 
     <span id="x" class="delete-icon" style="display:none;"><?php echo $this->Html->image('close.png',array('width'=>'23px')); ?></span> 
    </span> 
</div> 

основной вид страницы:

<div id="for_image0" class="inline-form" style="display:none;"> 
    <span> 
     <input type='file' name="data[ReportManagement][imageUploader]" id="file_upload" onchange="readURL(this);" /> 
     <span id="extension_error" style="color:red;"></span> 
     <br/> 
    </span> 
    <span id="previewPane"> 
     <img style="width:150px;float:left;" id="img_prev" src="#" /> 
     <span id="x" class="delete-icon" style="display:none;"><?php echo $this->Html->image('close.png',array('width'=>'23px')); ?></span> 
    </span> 
</div> 

страница контроллера:

if(!empty($this->request->data['ReportManagement']['imageUploader'.$i]['name'])){ 
    //debug($this->request->data['ReportManagement']['imageUploader'.$i]); 
    $image_type = @getimagesize($this->request->data['ReportManagement']['imageUploader'.$i]['tmp_name']); 
    $file_type = array('image/jpeg','image/gif','image/png','image/bmp'); 
    if(!in_array($image_type['mime'],$file_type)){ 
     return 1; 
     exit; 
    }   
    $name = $this->request->data['ReportManagement']['imageUploader'.$i]['name']; 
    $tmp_name = $this->request->data['ReportManagement']['imageUploader'.$i]['tmp_name']; 
    $random_number = $this->Smart->random_code(); 

    if(file_exists(WWW_ROOT.'issuereports/'.$name)){ 
     $name= $random_number.$this->request->data['ReportManagement']['imageUploader'.$i]['name']; 
    } 
} else { 
    $name = ''; 
} 
+2

Поместите дополнительную информацию о своей проблеме. – Anubhav

ответ

0

это один метод, вы можете попробовать это ..

Просмотреть:

<input type='file' multiple=true name="data[ReportManagement][imageUploader]" id="file_upload" onchange="readURL(this);" /> 

Этот метод позволит вам выбрать несколько файлов.