Jump to content

The ever lasting foreach problem


drisate

Recommended Posts

Hey guys i am having a small problem i have a forme that looks like this

 

<div id="new_link_fields0">
<div id="form_source0">
	<span class="r">Nom: <input name="nom[]0"><input type="hidden" value="1" name="i[]0">
	<input type="file" size="30" name="mp3[]0"><br>
 </span></div>
<div id="form_source1">
	<span class="r">Nom: <input name="nom[]1"><input type="hidden" value="1" name="i[]1">
	<input type="file" size="30" name="mp3[]1"><br>
 </span></div>
<div id="form_source2">
	<span class="r">Nom: <input name="nom[]2"><input type="hidden" value="1" name="i[]2">
	<input type="file" size="30" name="mp3[]2"></span></div>
</div>

 

It's auto generated so i can't change it ... I use this PHP code

 

$i=0;
foreach ($_POST[i] as $value){

$file_name = $_FILES['mp3']['name'][$i];
$file_tmp = $_FILES['mp3']['tmp_name'][$i];

echo "The file ".$file_name." is number $i<br>";
$i++;
}

 

The problem i have is even if i fill up everything i end up with this result

 

The file djj.mp3 is number 0

The file is number 1

The file is number 2

 

Only the first one is taken in charge ... so i made a

 

echo '<pre>$_POST:' . print_r($_POST,true) . '</pre>';
echo '<pre>$_FILES:' . print_r($_FILES,true) . '</pre>';

 

and i got

 

$_POST:Array
(
   [nom] => Array
       (
           [0] => 01
           [1] => 02
           [2] => 03
       )

   [i] => Array
       (
           [0] => 1
           [1] => 1
           [2] => 1
       )

   [btn_name3] => Suivant
)
$_FILES:Array
(
   [mp1] => Array
       (
           [name] => Array
               (
                   [0] => 782718_2599_60sec.mp3
               )

           [type] => Array
               (
                   [0] => audio/mpeg
               )

           [tmp_name] => Array
               (
                   [0] => /tmp/php6ALwV4
               )

           [error] => Array
               (
                   [0] => 0
               )

           [size] => Array
               (
                   [0] => 724575
               )

       )

   [mp2] => Array
       (
           [name] => Array
               (
                   [0] => 782718_2599_60sec.mp3
               )

           [type] => Array
               (
                   [0] => audio/mpeg
               )

           [tmp_name] => Array
               (
                   [0] => /tmp/phpXIXX7F
               )

           [error] => Array
               (
                   [0] => 0
               )

           [size] => Array
               (
                   [0] => 724575
               )

       )

   [mp3] => Array
       (
           [name] => Array
               (
                   [0] => 782718_2599_60sec.mp3
               )

           [type] => Array
               (
                   [0] => audio/mpeg
               )

           [tmp_name] => Array
               (
                   [0] => /tmp/phpEWvorz
               )

           [error] => Array
               (
                   [0] => 0
               )

           [size] => Array
               (
                   [0] => 724575
               )

       )

)

 

Soe everything is uploaded but for some reason it's not working when using the vars after the first loop

 

$file_name = $_FILES['mp3']['name'][$i];

$file_tmp = $_FILES['mp3']['tmp_name'][$i];

 

Any ideas?

 

is even $_FILES['mp3']['name'][$i] working to specify what aray to use since eveything is is $_FILES['mp3']

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.