0

This is the controller to upload two images.The first function is a do-upload and the second function is do_upload 2.

<?php
if (!defined('BASEPATH'))
    exit('No direct script access allowed');
class Upload_Controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index(){
        $this->load->view('file_view', array(
            'error' => ' '
            ));
    }

    public function file_view()
    {
        $this->load->view('file_view', array(
            'error' => ' '
            ));
    }

    public function do_upload()
    {
        $config = array(
            'upload_path' => "./uploads/",
            'allowed_types' => "gif|jpg|png|jpeg|pdf",
            'overwrite' => TRUE,
            // Can be set to particular file size , here it is 2 MB(2048 Kb)
            'max_size' => "2048000",
            'max_height' => "768",
            'max_width' => "1024"
            );
        $this->load->library('upload', $config);
        if ($this->upload->do_upload()) {
            $data = array(
                'upload_data' => $this->upload->data()
                );
            $this->load->view('file_view', $data);
        } else {
            $error = array(
                'error' => $this->upload->display_errors()
                );
            $this->load->view('file_view', $error);
        }
    }

    public function do_upload2()
    {
        $config = array(
            'upload_path' => "./uploads/index2/",
            'allowed_types' => "gif|jpg|png|jpeg|pdf",
            'overwrite' => TRUE,
            // Can be set to particular file size , here it is 2 MB(2048 Kb)
            'max_size' => "2048000",
            'max_height' => "768",
            'max_width' => "1024"
            );
        $this->load->library('upload', $config);
        if ($this->upload->do_upload()) {
            $data = array(
                'upload_data' => $this->upload->data()
                );
            $this->load->view('file_view', $data);
        } else {
            $error = array(
                'error1' => $this->upload->display_errors()
                );
            $this->load->view('file_view', $error);
        }
    }
}

?>

this is the file_view to upload two images and view two images. the problem with this code is when I upload one image it previews only that image. Can somebody help me to preview the both images simultaneously in the view?

<?php echo form_open_multipart( 'upload_controller/do_upload');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>

<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
    <li></li>
    <img alt="Your uploaded image" src="<?=base_url(). 'uploads/' . $upload_data['file_name'];?>">
</ul>

<?php echo form_open_multipart( 'upload_controller/do_upload2');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>

<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
    <li></li>
    <img alt="Your uploaded image" src="<?=base_url(). 'uploads/index2/' . $upload_data['file_name'];?>">
</ul>
<p>
    <?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>
Pathik Vejani
  • 4,263
  • 8
  • 57
  • 98
Dushee
  • 255
  • 5
  • 17

0 Answers0