Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Not Moving Files To Destination Folder
#1

Hello Fams,
  Please help me with this codeigniter upload form. I am uploading several images in the database using the input file multiple. I sense the error has to do with my .htaccess file cos I have downloaded an example from a site and the example code successfully moved the file to the destination folder(the directory didn't have .htaccess file to remove index.php file from url but my project directory implemented .htaccess file to remove index.php from the url) but when i tested the same code in my project I got the error :

"The upload path does not appear to be valid" using the display_error() method of CodeIgniter but the fact is that the upload path is correct. I suspected my .htaccess to be the error. Look at my upload code below :

    function doUpload()
        {
        $data2 = array();
       
        //check if the submit button is posted and if the multiple file upload is not empty
        if(!empty($_FILES['productphotos']['name']))
        {   
            $filesCount = count($_FILES['productphotos']['name']);
            for($i = 0; $i < $filesCount; $i++)
            {
              //if(!empty($_FILES['productphotos']['name'][$i]))
              //{
                $_FILES['file']['name'] = $_FILES['productphotos']['name'][$i];
                $_FILES['file']['type'] = $_FILES['productphotos']['type'][$i];
                $_FILES['file']['tmp_name'] = $_FILES['productphotos']['tmp_name'][$i];
                $_FILES['file']['error'] = $_FILES['productphotos']['error'][$i];
                $_FILES['file']['size'] = $_FILES['productphotos']['size'][$i];

                $uploadPath = './Products/';
                $config['upload_path'] = $uploadPath;
                $config['allowed_types'] = 'gif|jpg|jpeg|png';
                $config['max_size']    = '5000'; // max_size in kb
$config['file_name'] = $_FILES['productphotos']['name'][$i];
               
                //load upload library
                $this->load->library('upload', $config);
                //$this->upload->initialize($config);

                //upload the files
                if($this->upload->do_upload('file'))
                {
                  //Get data about the files
                    $fileData = $this->upload->data();
                    $uploadData[$i]['file_name'] = $fileData['file_name'];
                    //$uploadData[$i]['created'] = date("Y-m-d H:iConfused");
                    //$uploadData[$i]['modified'] = date("Y-m-d H:iConfused");
                   
                    //initialise file array
                    $datas['filenames'][] = $filename;

                    $this->loadRecord(); 
                } // closes if

                else
                {
                  echo $this->upload->display_errors();           
                } //closes else
            }  //closes for loop

//Check if data  available in the upload data and if uploaded
            if(!empty($uploadData[i]))
            {
              //Insert file information into the database
              $data2 = array(
                  'WZB_ProductCode'=>$this->input->post('productcode'),
                  'ProductGrade'=>$this->input->post('productgrade'),
                  'WZB_ProductName'=>$this->input->post('productname'),
                  'WZB_ProductDescription'=>$this->input->post('productdescription'),
                  'WZB_QuantityPerUnit'=>$config['quantityperunity'],
                  'WZB_UnitPrice'=>$this->input->post('unitprice'),
                  'WZB_ProductOwner'=>$this->input->post('productowner'),
                  'WZB_CategoryName'=>$this->input->post('categoryname'),
                  'WZB_VerifiedByAgent'=>$this->input->post('verifiedbyagent'),               
                  'ProductPhotoName'=>$uploadData[i],
                  'Addedby'=>$this->input->post('addedby')
                );
             
              $this->db->insert('wzb_adverts', $data2);                     
              $this->session->set_flashdata('Added Successfully','Record  successfully added');
              $this->loadRecord(); 

              //$insert = $this->file->insert($uploadData);
              //$statusMsg = $insert?'Files uploaded successfully.':'Some problem occurred, please try again.';
              // $this->session->set_flashdata('statusMsg',$statusMsg);
          // } // Closes this if for database for checking if file is uploaded 
                                                           
        }  //closes if for checking if form is submitted and if file is uploaded
        }

This is my .htaccess code :

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]

I suspected my .htaccess file cos same code that i tested in a different directory on same localhost worked fine(the directory didn't have .htaccess file to remove index.php file from url but my project directory implemented .htaccess file to remove index.php from the url). Moreover, i want to insert each file that is uploaded by the file upload in the database. How do i get this accomplished. Can I just insert each file name uploaded in a column separated by comma and i should insert each image file name with it's data in a different row.

Thank you in advance.
Reply


Messages In This Thread
CodeIgniter Not Moving Files To Destination Folder - by olammieconcept - 12-19-2019, 10:55 PM



Theme © iAndrew 2016 - Forum software by © MyBB