Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 05-14-2008, 08:48 PM foreach loop prob
Junior Talker

Posts: 1
Trades: 0
Hey guys i am having a small problem i have a forme that looks like this

PHP Code:
<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>
&
nbsp;</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>
&
nbsp;</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
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

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

Code:
$_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

PHP Code:
$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']

Last edited by phpecono; 05-14-2008 at 08:49 PM..
phpecono is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-15-2008, 05:20 AM Re: foreach loop prob
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
Taking a brief look at this, it seems like you just have your loop code wrong. Try

PHP Code:
foreach ($_POST as $i=>$value){
  
$file_name $_FILES['mp3']['name'][$i];
  
$file_tmp $_FILES['mp3']['tmp_name'][$i];
  echo 
"The file ".$file_name." is number $i<br>";

__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to foreach loop prob
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10837 seconds with 12 queries