0

I am having multiple fields of file upload. In the start there is no field when a user clicks on add button it displays a file upload field

In View

PHP    
<?php echo $i = 0;?>

Javascript
var i = '<?php echo $i?>';  

<input type="file" name="product_image_' + i +'"/>

When i submit the form if displays this output

Array
(
    [product_image_1_] => Array
        (
            [name] => 25412_D80_backsanspic.png
            [type] => image/png
            [tmp_name] => C:\xampp\tmp\php68.tmp
            [error] => 0
            [size] => 355623
        )

    [product_image_2_] => Array
        (
            [name] => 25420_D40_right.png
            [type] => image/png
            [tmp_name] => C:\xampp\tmp\php69.tmp
            [error] => 0
            [size] => 347694
        )

    [product_image_3_] => Array
        (
            [name] => 26135_P6000_34r.png
            [type] => image/png
            [tmp_name] => C:\xampp\tmp\php6A.tmp
            [error] => 0
            [size] => 420441
        )

    [product_image_4_] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )

)

You can see there is underscore in each file upload field. I dont understand how this is possible. Also if i do this

echo $_FILES['product_image_4_']['error'];

It displays output but this does not

echo $_FILES['product_image_4']['error'];

Instead it produces error undefined index product_image_4 Any suggestion. I am using pyrocms built on codeigniter.

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103

2 Answers2

0

Your Javascript code is adding extra underscore you need to check it out. Add more fields and view the page source. If it already has (_) in the name. You might be appending extra underscore in your java-script code.

Sachin Prasad
  • 5,365
  • 12
  • 54
  • 101
0

I have found an alternate solution for this problem i am removing _ with php for the time being not a perfect solution but it lets me go on with my work.

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103