2 Replies - 2138 Views - Last Post: 25 October 2010 - 07:04 PM Rate Topic: -----

#1 Guest_maxh*


Reputation:

Scandir Array display without file extensions?

Posted 25 October 2010 - 05:06 PM


$FolderPath = 'uploads/';
$dh = opendir($FolderPath);
	while (false !== ($filename = readdir($dh))) {
$files[] = $filename;
		}



I'm using this to create a list of my files in the 'uploads/' path.

When I view the array it shows, for example, my_file_name.php

How do I make it so the array only shows the filename and not the extension?

Is This A Good Question/Topic? 0

Replies To: Scandir Array display without file extensions?

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Scandir Array display without file extensions?

Posted 25 October 2010 - 06:09 PM

Chop off everything after the last occurrence of '.' before adding each filename to $files?

$FolderPath = 'uploads/';
$dh = opendir($FolderPath);
while (false !== ($filename = readdir($dh)))
{
	$files[] = substr($filename, 0, strrpos($filename, '.'));
}



Of course, if you have example.gif and example.jpg, you're gonna have example in there twice.

This post has been edited by Valek: 25 October 2010 - 06:16 PM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_maxh*


Reputation:

Re: Scandir Array display without file extensions?

Posted 25 October 2010 - 07:04 PM

Thanks a lot! Works good

And the files I have are all numbered sequentially so that should not be an issue.

Thanks again
Was This Post Helpful? 0

Page 1 of 1