0

Hi,

Can anyone help me for uploading files into different folders using Code Igniter.
Right now all files goes into a single folder insted of different folder even I have set path for them in config variable.

Thanks

6
Contributors
18
Replies
40
Views
5 Years
Discussion Span
Last Post by A@DFGFGN.IN
0

Thanks mschroeder, for your reply.

Actually problem is solved with this

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

I done this for each image file while setting path into config variable.
But I am new to CI so dont know how above 2 nd line of code works .

Could you tell me your reply will be preceious for me.

Thanks,
Nalini

0

here is an example from user guide

<?php

class Upload extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->helper(array('form', 'url'));
	}

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

	function do_upload()
	{
		$config['upload_path'] = './uploads/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '100';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';

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

		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());

			$this->load->view('upload_form', $error);
		}
		else
		{
			$data = array('upload_data' => $this->upload->data());

			$this->load->view('upload_success', $data);
		}
	}
}
?>
0

This will upload images into a single folder.Needed to upload 3 images of a single form into different folder.

0

This will upload images into a single folder.Needed to upload 3 images of a single form into different folder.

you can do a trick:

function do_upload($path)
	{
		$config['upload_path'] = $path;
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '100';
		$config['max_width']  = '1024';
		$config['max_height']  = '768';

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

		if ( ! $this->upload->do_upload())
		{
			$error = array('error' => $this->upload->display_errors());

			$this->load->view('upload_form', $error);
		}
		else
		{
			$data = array('upload_data' => $this->upload->data());

			$this->load->view('upload_success', $data);
		}
	}

Then each call in loop (for loop or while: whatever) supply different path!

0

Hello evstevemd,
Done as per above reply
It gives error
Fatal error: Call to undefined function do_upload() in C:\xampp\htdocs\project1\system\application\controllers\admin\front.php on line 122

Thanks

0

No tried like this

for($i=0;$i<3;$i++)
		  {
		  
		     if($i==0)
			 {
			   $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/thumb_img';
			   do_upload($path);
			 }
			 if($i==1)
			 {
			    $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/large_img';
				do_upload($path);
			 }
			 if($i==2)
			 {
			   $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/join_img';
			  do_upload($path);
			 }
			 
		  
		  
		  }
		  

function do_upload($path)
    {
   
      $config['upload_path'] = $path;
      $config['allowed_types'] = 'gif|jpg|png';
  
      $config['max_size'] = '100';
  
      $config['max_width'] = '1024';

      $config['max_height'] = '768';
   
   $this->load->library('upload', $config);
  
      if ( ! $this->upload->do_upload())
     {
 
      $error = array('error' => $this->upload->display_errors());
 
      $this->load->view('upload_form', $error);
 
      }
 
      else
  
      {
  
      $data = array('upload_data' => $this->upload->data());
 
      //$this->load->view('upload_success', $data);
      }
 
   }

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0
<?php
class Front extends Controller
{

	  function Front()
	  {
			parent::Controller();	
			if($this->session->userdata('adminid')=='')
			{
				redirect(base_url().'index.php/admin/login');
			}
			$this->load->model('login_model');
			
	 }
	 function index()
	 {
	  $this->load->view('admin/index');
	 }
	function manage_front()
	{
	   
		$data['front']=$this->login_model->getAllfront();
		
		$this->load->view('admin/manage_front',$data);
	}	
	function add_front($id)
	{
	
	   
	   $data['frontdata']=NULL;
	   $data['fab_id']=$id;
	   $this->load->view('admin/add_front',$data);
	
	}
	function do_upload($path)
   {
 
		 $config['upload_path'] = $path;
		 $config['allowed_types'] = 'gif|jpg|png';
		 $config['max_size'] = '100';
		 $config['max_width'] = '1024';
		 $config['max_height'] = '768';
	   		$this->load->library('upload', $config);
   
	  if ( ! $this->upload->do_upload())
		{
		      $error = array('error' => $this->upload->display_errors());
		      //$this->load->view('upload_form', $error);
		}
		else
	    {
		   $data = array('upload_data' => $this->upload->data());
	    }
  
 }


	function action($stat,$id)
	{
	   
		if($stat==1)
		{
		
		  $string = mt_rand();
	  
	  
	      extract($_POST);
		 
		    $fabric_id=$id;
		    $front_short_images=$_FILES['front_short_images']['name'];
		    $front_middle_images=$_FILES['front_middle_images']['name'];
		    $front_join_image=$_FILES['front_join_image']['name'];
			for($i=0;$i<3;$i++) 
			{ if($i==0) 
			  { 
			     $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/thumb_img'; 
				 do_upload($path);
			  }
			 if($i==1)
			  {
			     $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/large_img';
				  do_upload($path);
			  } 
			  if($i==2) 
			  {  $path = ADMIN_DATA.'uploaded/shirt/parts/'.$fabric_id.'/front/join_img'; 
			  do_upload($path); 
			  }
			  
	      }
		   
		    $data['frontdata']=$this->login_model->create_frontstyle($fabric_id);
		   $this->session->set_flashdata('flash', 'Front Style added successfully.');
		   redirect('admin/front/manage_front'); 
		  
	  }
}
0

Ok not an issue ,Actually I have done it another way but that is not good way .

0
function set_folder()
    {
        // print_r($this->upload->data());
            $data = $this->upload->data();

            $udata = $this->upload_model->insert_file($data['file_name'], $_POST['title']);
            /**********create folder**************/ 
            $location = $_SERVER['DOCUMENT_ROOT'].'/online_docket/uploaded_doc/';
            $folderName = $_POST["title"];

            $folderName = str_replace(" ", "_", $folderName); 
            $folderName = strtolower($folderName);
            //echo $location.$folderName ;
            //echo $file_name ;

            if(!file_exists($folderName) && !is_dir($folderName))
            {   
                mkdir($location.$folderName, 0777, TRUE);

            }
    }

call this class in ur do_upload class in controller.

1

I thought this question was just posted some 20+ hours ago, and then I just realized it was awaken from the bone files of two years ago. :).

Votes + Comments
Do they have an update here?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.