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

I think very few people know about Code Igniter :(

How about you show us the code you're using so we can formulate a solution.

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

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);
		}
	}
}
?>

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

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!

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

do_upload($path)<--------------------did you forget $path??

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);
      }
 
   }

did you do it all in controller class in the first code only modifying the do upload?

Yes I have done in controller class only .

Yes I have done in controller class only .

can you post current code?

<?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'); 
		  
	  }
}

I will test later, now I have another thing to do!

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

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.

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. :).

commented: Do they have an update here? +0
        code is not working
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.