What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Some PHP help, yet again

Some PHP help, yet again
Author: Message:
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. Some PHP help, yet again
How would I, using PHP, read every file inside a directory and produce a list of all the files with a "bsp" extension, but not including the extention.
So basically, read a maps/ folder, get every file name, and list it, but only if the extension is a .bsp?
09-12-2009 01:28 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: Some PHP help, yet again
php code:
<?php
foreach (glob("/path/to/maps/*.bsp") as $file) {
    $info = pathinfo($file);
    echo $info['filename']; // requires PHP 5.2.0 !!!
}
?>
If you're running on PHP < 5.2.0, you can get the file name using substr() and strrpos():
php code:
    $info = pathinfo($file);
    $basename = $info['basename'];
    echo substr($basename, 0, strrpos($basename, '.'));

This post was edited on 09-12-2009 at 04:03 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
09-12-2009 04:02 PM
Profile E-Mail PM Web Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: Some PHP help, yet again
Thank you Matti :)

How could I then count the number of .bsp files and display that?

Also I am using the following code(very messy, I know) to get all images inside a directory and display them on after another with their names. How could I make them display in a 3 column table, each cell holding an image, and an image name?
php code:
Map images:<br><Br>
<?php
$folder = opendir("C:\Inetpub\wwwroot\lgsl\lgsl_files\maps\source\zombie_master");

$pic_types = array("jpg", "jpeg", "gif", "png");

$index = array();

while ($file = readdir ($folder)) {

  if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
    {
        array_push($index,$file);
    }
}

closedir($folder);
?>
<?php
$path = "C:\Inetpub\wwwroot\lgsl\lgsl_files\maps\source\zombie_master";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if(ereg("(.*)\.(jpg|bmp|jpeg|png|gif)", $file)){
echo "$file<br><img src='http://sammyservers.com/lgsl/lgsl_files/maps/source/zombie_master//$file' alt='$file'><br />";
}


}
closedir($dir_handle);


?>

This post was edited on 09-12-2009 at 07:49 PM by Jimbo.
09-12-2009 07:44 PM
Profile E-Mail PM Find Quote Report
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
RE: Some PHP help, yet again
You can use the count(); function for that. Something along the lines of $num_files = count($files_array).
09-13-2009 12:12 PM
Profile PM Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: Some PHP help, yet again
Thanks, one last thing, how could I compare 2 directories, say a maps directory where all files are a .bsp, and then an images directory where all files are .jpg. How could I compare the filename of these, and then output which .bsp do not have .jpg equivalents?
09-14-2009 07:22 AM
Profile E-Mail PM Find Quote Report
Baggins
Full Member
***

Avatar
B000ALFAZO

Posts: 387
Reputation: 13
29 / Male / Flag
Joined: Oct 2006
RE: Some PHP help, yet again
quote:
Originally posted by Jimbo
Thanks, one last thing, how could I compare 2 directories, say a maps directory where all files are a .bsp, and then an images directory where all files are .jpg. How could I compare the filename of these, and then output which .bsp do not have .jpg equivalents?
http://ca.php.net/manual/en/function.array-diff.php
09-14-2009 11:29 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On