PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How to upload multiple image in cakephp?

 April 22, 2022     cakephp-1.3, cakephp-2.3, file-upload, jquery, php     No comments   

Issue

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 = '';
}   

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.



Answered By - Arsh
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing