shark007 Posted August 7, 2007 Share Posted August 7, 2007 Howdy. I have a function that picks a random file (xxx.mp3) from a directory. I need to then get the name of that file in string form. So if it picks xxx.mp3 (rather than yyyy.mp3), I need to end up with "xxx". Is there a function (or other easy way) of doing this? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/63771-file-name/ Share on other sites More sharing options...
Barand Posted August 7, 2007 Share Posted August 7, 2007 <?php $filename = 'xxx.mp3'; list ($name, $ext) = explode ('.', $filename); echo $name; Quote Link to comment https://forums.phpfreaks.com/topic/63771-file-name/#findComment-317807 Share on other sites More sharing options...
tarun Posted August 7, 2007 Share Posted August 7, 2007 <?php $pathinfo = pathinfo("xxx.mp3"); echo $pathinfo["dirname"]; // Gets The Dir That xxx.mp3 Is Found In (uploads/music/mp3s) echo $pathinfo["basename"]; // Gets The File Name And Extension Together (xxx.mp3) echo $pathinfo["extension"]; // Gets The File Extension (mp3) echo $pathinfo["filename"]; // Gets The Filename (xxx) --- Since PHP 5.2.0 ?> ThanX, Tarun Quote Link to comment https://forums.phpfreaks.com/topic/63771-file-name/#findComment-317812 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.