Question

I have a problem in loading multiple image, I can only load single image and when I select the next image the previous image get lost.

My view page is like this:

<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>

main view page:

<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>

controller page:

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 = '';
}   
Was it helpful?

Solution

this is one method,you can try this..

In view:

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

This method will allow you to select multiple files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top