Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    How would I add an exclusion to all files and folders except .mp3?

    PHP
    2
    5
    320
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • MPG Radio
      MPG Radio last edited by

      <?php
      $dirpath="./";
      $handle = opendir($dirpath);
      print '<div id="response"></div>';
      print "<table>";
      $i=0;
      while($file = readdir($handle)) {
      if($file!="." && $file!="..") {
      print "<tr><td><input type='text' id='{$i}_new_name' value='{$file}' /></td><input type='hidden' id='{$i}_old_name' value='{$file}' /></td><td><input type='button' name='change' class='change_class' value='Change Name' id='{$i}' /></td></tr>";
          $i++;
      }
      }
      print "</table>";
      ?>
      
      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by avan

        Hey @MPG-Radio

        Thanks for the tip!

        Here is an example on how to check if a file name ends with the extension .mp3

        Let me know if you need help getting it to work in your code.

            $src_file_name = 'something.MP3';
            $ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION)); // Using strtolower to overcome case sensitive
            $mp3 = 'mp3';
            if (strcasecmp($ext, $mp3) == 0) {
                echo "it's mp3";
            } else {
                echo 'not mp3';
            }
        

        So maybe something like this:

        <?php
        $dirpath="./";
        $handle = opendir($dirpath);
        print '<div id="response"></div>';
        print "<table>";
        $i=0;
        while($file = readdir($handle)) {
        $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
        $mp3 = 'mp3';
        if($file!="." && $file!=".." && strcasecmp($ext, $mp3) == 0 ) {
        print "<tr><td><input type='text' id='{$i}_new_name' value='{$file}' /></td><input type='hidden' id='{$i}_old_name' value='{$file}' /></td><td><input type='button' name='change' class='change_class' value='Change Name' id='{$i}' /></td></tr>";
            $i++;
        }
        }
        print "</table>";
        ?>
        
        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by avan

          Hey @MPG-Radio

          Thanks for the tip!

          Here is an example on how to check if a file name ends with the extension .mp3

          Let me know if you need help getting it to work in your code.

              $src_file_name = 'something.MP3';
              $ext = strtolower(pathinfo($src_file_name, PATHINFO_EXTENSION)); // Using strtolower to overcome case sensitive
              $mp3 = 'mp3';
              if (strcasecmp($ext, $mp3) == 0) {
                  echo "it's mp3";
              } else {
                  echo 'not mp3';
              }
          

          So maybe something like this:

          <?php
          $dirpath="./";
          $handle = opendir($dirpath);
          print '<div id="response"></div>';
          print "<table>";
          $i=0;
          while($file = readdir($handle)) {
          $ext = strtolower(pathinfo($file, PATHINFO_EXTENSION));
          $mp3 = 'mp3';
          if($file!="." && $file!=".." && strcasecmp($ext, $mp3) == 0 ) {
          print "<tr><td><input type='text' id='{$i}_new_name' value='{$file}' /></td><input type='hidden' id='{$i}_old_name' value='{$file}' /></td><td><input type='button' name='change' class='change_class' value='Change Name' id='{$i}' /></td></tr>";
              $i++;
          }
          }
          print "</table>";
          ?>
          
          Reply Quote 0
            1 Reply Last reply

          • MPG Radio
            MPG Radio last edited by

            All is well now thank your efficient help...works just fine.....

            Reply Quote 1
              1 Reply Last reply

            • MPG Radio
              MPG Radio last edited by

              Ok shoot, my php version must be a problem I cant seem to change the name nothing happens when I click the change name button but works fine on local machine....humm.

              Reply Quote 0
                1 Reply Last reply

              • MPG Radio
                MPG Radio last edited by

                Ok my bad was serving over https.....duh...thank you.

                Reply Quote 0
                  1 Reply Last reply

                • First post
                  Last post