Welcome Guest, Not a member yet? Register   Sign In
[Image Upload Problem] - The image doesn't upload altough another model with the same structure works
#1

[eluser]Unknown[/eluser]
OK. The problem that i have is that the module doesn't upload the image. Another model with the same structure but that leads to another path works.

The model is this:

Code:
<?php
class Poze_produse_model extends Model {
    
    var $dir_poze;
    
    function Poze_prod_model()
    {
        parent::Model();
        $folder = $this->input->post('Categorie_Produs');
        $folder = str_replace(' ', '_', $folder );
        $this->dir_poze = realpath(APPPATH . '../poze/produse'.'/'.$folder);
        
    }
    
    function submit_poze()
    {
        $rows = $this->input->post('rows');
        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->dir_poze,
            'max_size' => 2000,
            'encrypt_name' => TRUE
        );
        $this->load->library('upload', $config);
        for($i = 1; $i <= $rows; $i++) {
            $field_name = 'imagine'.$i;
            $this->upload->do_upload($field_name);
            $image_data = $this->upload->data();
            $data = array (
                        'Categorie_Produs' => $this->input->post('Categorie_Produs'),
                        'COD' => $this->input->post('cod'.$i),
                        'Denumire_Fisier' => $image_data['file_name']
            );
            $this->db->insert('poze_produse',$data );
        }
            
    }
}

The view (this is only the content view which is nested in a general view):

Code:
<div id="caracteristici">
    &lt;form method="post" action="../submit_adauga_poze" enctype="multipart/form-data"&gt;
    &lt;input type="hidden" name="rows" value="&lt;?php echo $rows ?&gt;" /&gt;
        <ul id="form_admin" class="nobullet">
            <li class="label_before">
                <label>Selecteaza Produs:</label>
                <div>
                    <select size="1" name="Categorie_Produs">
                        <option selected value="Selectati Produsul" >Selectati Produsul </option>
                        &lt;?php
                        $this->Functii->cat_prod_drop();
                        ?&gt;    
                    </select>
                </div>
            </li>
        </ul>
        <ul id="form_admin" class="nobullet">
            <div class="light">
                <li class="label_before">
                    <label>Cod Produs:</label>
                    <div>
                        &lt;input type="text" size="25" name="cod1" /&gt;
                    </div>
                        <label>Imagine Produs:</label>
                    <div>
                        &lt;input type="file" name="imagine1" size="25" /&gt;
                    </div>
                </li>
            </div>
            <li>
                &lt;input type="submit" value="Adauga" /&gt;
            </li>
        </ul>
    &lt;/form&gt;
</div>

And the class:

Code:
&lt;?php
class Admin extends Controller {
    
    var $rows;
    
    function __construct()
    {
        parent::Controller()  
    }

function adauga_poze($rows = 1)
    {
        $data['din_content'] = 'adauga_poze_view';
        $data['rows'] = $rows;
        $this->load->view('admin/admin_view', $data);
    }
  
    function submit_adauga_poze()
    {
        $this->load->model('Poze_produse_model');
        $this->Poze_produse_model->submit_poze();
        redirect('admin/adauga_poze/1');
        
    }

From the model/controller and view i deleted the unnecessary parts.

The code should work like this:

A user can select how many pictures he can upload (the $rows variable does this. In the view i deleted the function that populates it with the necessary image fields and only left a filed for testing purposes)

The problem i think is with the path. I tried changing the path to be fixed but this didn't work either. If I changed
Code:
$config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->dir_poze,
            'max_size' => 2000,
            'encrypt_name' => TRUE
        );
to

Code:
$config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path' => $this->dir_poze.'/',
            'max_size' => 2000,
            'encrypt_name' => TRUE
        );

The file was then uploaded in the root folder of my diskdrive (E:\)

I use Xampp on Windows 7 X64.
#2

[eluser]Unknown[/eluser]
hmm.....no one?




Theme © iAndrew 2016 - Forum software by © MyBB