Answers for "file upload in codeigniter"

PHP
0

get upload error codeigniter

if($this->input->post())
{
   $file_element_name = 'image';  //this is the name of your input file. for example "image"
   if ($_FILES['image']['name']!= "")
   {
      $config['upload_path'] = './uploads/';
      $config['allowed_types'] = 'gif|jpg|png|exe|xls|doc|docx|xlsx|rar|zip';
      $config['max_size']      = '8192'; 
      $config['remove_spaces']=TRUE;  //it will remove all spaces
      $config['encrypt_name']=TRUE;   //it wil encrypte the original file name
      $this->load->library('upload', $config);

      if (!$this->upload->do_upload($file_element_name))
      {
         $error = array('error' => $this->upload->display_errors());
         $this->session->set_flashdata('error',$error['error']);
         redirect('controller_name/function_name','refresh');
      }
      else
      {
         $data = $this->upload->data();
         return $data['file_name'];          
      }
      $this->session->set_flashdata('msg','success message');
      redirect('controller_name/function_name','refresh');
   }
   else
   {
        //if no file uploaded the do stuff here
   } 
}
Posted by: Guest on June-12-2020
0

upload multiple files in codeigniter

private function upload_files($path, $title, $files)
    {
        $config = array(
            'upload_path'   => $path,
            'allowed_types' => 'jpg|gif|png',
            'overwrite'     => 1,                       
        );

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

        $images = array();

        foreach ($files['name'] as $key => $image) {
            $_FILES['images[]']['name']= $files['name'][$key];
            $_FILES['images[]']['type']= $files['type'][$key];
            $_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
            $_FILES['images[]']['error']= $files['error'][$key];
            $_FILES['images[]']['size']= $files['size'][$key];

            $fileName = $title .'_'. $image;

            $images[] = $fileName;

            $config['file_name'] = $fileName;

            $this->upload->initialize($config);

            if ($this->upload->do_upload('images[]')) {
                $this->upload->data();
            } else {
                return false;
            }
        }

        return $images;
    }
Posted by: Guest on October-30-2020
0

image upload in codeigniter 3

<!DOCTYPE html>
<html>
<head>
    <title>CodeIgniter Image Upload</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <div>
        <h3>Select an image from your computer and upload it to the cloud</h3>
        <?php
                if (isset($error)){
                    echo $error;
                }
            ?>
            <form method="post" action="<?=base_url('store-image')?>" enctype="multipart/form-data">
                <input type="file" id="profile_image" name="profile_image" size="33" />
                <input type="submit" value="Upload Image" />
            </form>
    </div>
</body>
</html>
Posted by: Guest on August-23-2021
0

upload image in codeigniter 3 source code

<!DOCTYPE html>
<html>
<head>
    <title>Image Upload Results</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <div>
        <h3>Congratulations, the image has successfully been uploaded</h3>
        <p>Click here to view the image you just uploaded
            <?=anchor('images/'.$image_metadata['file_name'], 'View My Image!')?>
        </p>

        <p>
            <?php echo anchor('upload-image', 'Go back to Image Upload'); ?>
        </p>
    </div>
</body>
</html>
Posted by: Guest on December-18-2020

Code answers related to "file upload in codeigniter"

Browse Popular Code Answers by Language