0

I use codeigniter and in upload file I have problem. file_name is produced Repetitiously.

My Model: (db_category)

public function do_upload($route = "./category-pic/") {
    $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png',
            'upload_path'   => $route,
            'encrypt_name'  => 'TRUE',
            'max_size'      =>  3000
    );
    $this->load->library("upload", $config);
}

My Controller:

$this->db_category->do_upload("./product-pic/");
foreach ($_FILES as $key => $value) {
    $this->upload->do_upload($key);
    $data_name = $this->upload->data();
    $k++;
    if (is_uploaded_file($_FILES['file'.$k]['tmp_name'])) {
        // This is produced Repetitiously sometimes for different pictures.
        echo $data_name['file_name']. " ****** ";
    }
}

My view is simple and static like :

echo '<input type="file" name="file1" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file4" id="my_uploader" style="width: 210px;" />';

NOTE: All pictures uploads fine with their own names, but the problem is in $data_name['file_name'].

What is the problem? Thanks.

2 Answers 2

1

instead of

$data_name['file_name'];

use

$_FILES['file'.$k]['name'];
Sign up to request clarification or add additional context in comments.

12 Comments

Thank you so much. But there is a problem. Codeigniter changes the picture name by 'encrypt_name' => 'TRUE' but your php code does not, and I insert to database with original name.
can you please show me the $data_name variable. echo "<pre>".$print_r($data_name)."</pre>";
You see, after first one, 3 of them are the same! But they are uploaded fine.
can show me the function which update the database please.
some how you need to refresh the $data_name variable.
|
0

Finally I found the answer! It was a bad mistake from view part.

Input files was not written in order. For example it was like this:

echo '<input type="file" name="file5" id="my_uploader" style="width: 210px;" />' ;
echo '<input type="file" name="file2" id="my_uploader" style="width: 210px;" />';
echo '<input type="file" name="file3" id="my_uploader" style="width: 210px;" />';

I don't know why this can cause problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.