Results 1 to 6 of 6

Thread: Problem passing multiple arguments to php script

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Problem passing multiple arguments to php script

    Hi all i have problem passing the multiple arguments to a php script . I call a script like beleow:

    mp3player.swf?playlist=playlist3.php?Id[]=3&Id[]=7

    from :

    main code:
    Code:
    <html>
    <head>
    <title>JW Flash MP3 Player</title>
    </head>
    <body>
    
    
     <object type="application/x-shockwave-flash" width="280" height="280"
        data="mp3player.swf?playlist=playlist.php?Id[]=5&Id[]=7">
      <param name="movie" value="mp3player.swf?playlist=playlist3.php?Id[]=3&Id[]=7" />
      </object>
    
    
    </body>
    </html>

    When i use the 1th part only which is in bold the scripts work fine and goes plays all songs from directory:

    Code:
    1th part
    while($i = readdir($fdir)) {
       // if a .mp3 string is found, add the file to the array
       if (strpos(strtolower($i),".mp3") !== false) {
      	   $playlist[$n] = $i;
      	   $n++;
      	} 
    }

    But when i remove 1th bold part and use 2th bold part it only plays for me the first song which is the first passed value but not the second passed value. Could any one help me what is wrong here ?Thanks

    Code:
    2th part:
    while($i = readdir($fdir)) {
       list($name, $ext) = explode('.', $i, 2);
       if(strtolower($ext) == 'mp3' && in_array($name, $_GET['Id'])){
             $playlist[$n] = $i;
             $n++;
          }
    }

    playlist3.php code with both bold part .When i run i use one of them each time
    Code:
    <?php
    
    
    
    
    // setting the directory to search for mp3 files
    $dir = "mp3/";
    
    
    
    // reading the directory and inserting the mp3 files in the playlist array
    $n = 0;
    $playlist = array();
    $fdir = opendir($dir);
    1th part
    while($i = readdir($fdir)) {
       // if a .mp3 string is found, add the file to the array
       if (strpos(strtolower($i),".mp3") !== false) {
      	   $playlist[$n] = $i;
      	   $n++;
      	} 
    }
    
    2th part:
    while($i = readdir($fdir)) {
       list($name, $ext) = explode('.', $i, 2);
       if(strtolower($ext) == 'mp3' && in_array($name, $_GET['Id'])){
             $playlist[$n] = $i;
             $n++;
          }
    }
    // close the directory and sort the array
    closedir($fdir);
    //array_multisort($playlist);
    
    //print_r($playlist);
    
    // echoing the playlist to flash
    echo "<player showDisplay=\"yes\" showPlaylist=\"no\" autoStart=\"yes\">\n";
    for ($i=0; $i<sizeof($playlist); $i++) {
       // for the title it filters the directory and the .mp3 extension out
       echo "  <song path=\"$dir$playlist[$i]\" title=\"".str_replace(".mp3","",$playlist[$i])."\" />\n";
    }
    echo "</player>";
    
    
    
    
    
    ?>

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem passing multiple arguments to php script

    I think your problem may be the use of brackets? Are the songs named using numbers, i.e 1,2,0 ? etc.

    Try this:
    PHP Code:
    rewinddir($fdir);

    while((
    $i readdir($fdir)) !== false) {
        list(
    $name$ext) = explode('.'$i2);
        if((
    strtolower($ext) == 'mp3') && in_array($name$_GET['Id'])){
            
    $playlist[$n] = $i;
            
    $n++;
        }

    The check for !== flase is important when using readdir() a check for equality is not enough. Notice also how I have used rewinddir() before to start searching the directory from the beginning.

    Also, if you use PHP 5, then you can edit and save the XML a lot easier by using Simple XML and DOM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem passing multiple arguments to php script

    Quote Originally Posted by visualAd
    I think your problem may be the use of brackets? Are the songs named using numbers, i.e 1,2,0 ? etc.

    Try this:
    PHP Code:
    rewinddir($fdir);

    while((
    $i readdir($fdir)) !== false) {
        list(
    $name$ext) = explode('.'$i2);
        if((
    strtolower($ext) == 'mp3') && in_array($name$_GET['Id'])){
            
    $playlist[$n] = $i;
            
    $n++;
        }

    The check for !== flase is important when using readdir() a check for equality is not enough. Notice also how I have used rewinddir() before to start searching the directory from the beginning.

    Also, if you use PHP 5, then you can edit and save the XML a lot easier by using Simple XML and DOM.
    Many thanks for u reply. i tried your code but no luck only first value get passed!! could u tell me how i can avoid using brackets and instead use Id=1,Id=2? i be happy if u help me .Thanks

  4. #4
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Problem passing multiple arguments to php script

    Unfortunatly you cannot do it any other waay (as far a I am aware in PHP). You could have a comma delimetered list and use explode to load it into an array when the script starts.

    For now, try replacing the quare brackets with their url encoded equivilents: [ = %5B and ] = %5D
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Problem passing multiple arguments to php script

    You need to use urlencode as the you have two '?' within the URL which will throw off php.
    PHP Code:
    <html>
    <head>
    <title>JW Flash MP3 Player</title>
    </head>
    <body>


     <object type="application/x-shockwave-flash" width="280" height="280"
        data="mp3player.swf?playlist=<?= urlencode('playlist3.php?Id[]=3&Id[]=7'?>">
      <param name="movie" value="mp3player.swf?playlist=playlist=<?= urlencode('playlist3.php?Id[]=3&Id[]=7'?>" />
      </object>


    </body>
    </html>
    Last edited by john tindell; Feb 8th, 2006 at 10:56 AM.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Problem passing multiple arguments to php script

    Quote Originally Posted by john tindell
    You need to use urlencode as the you have two '?' within the URL which will throw off php.
    PHP Code:
    <html>
    <head>
    <title>JW Flash MP3 Player</title>
    </head>
    <body>


     <object type="application/x-shockwave-flash" width="280" height="280"
        data="mp3player.swf?playlist=<?= urlencode('playlist3.php?Id[]=3&Id[]=7'?>">
      <param name="movie" value="mp3player.swf?playlist=playlist=<?= urlencode('playlist3.php?Id[]=3&Id[]=7'?>" />
      </object>


    </body>
    </html>
    Thank u for u reply. I tried your code by putting it inside php file and run it now the first song also does not play!!! Here i the code the out put in browser:
    Code:
    <html> 
    <head> 
    <title>JW Flash MP3 Player</title> 
    </head> 
    <body> 
    
    
    <object type="application/x-shockwave-flash" width="280" height="280" 
        data="mp3player.swf?playlist=playlist3.php%3FId%5B%5D%3D3%26Id%5B%5D%3D7"> 
      <param name="movie" value="mp3player.swf?playlist=playlist=playlist3.php%3FId%5B%5D%3D3%26Id%5B%5D%3D7" /> 
      </object> 
    
    
    </body> 
    </html>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width