Skip to content
WJunction - Webmaster Forum

SMF > IPB Converters - Issue with paths in windows

Status
Not open for further replies.
PHP:
foreach (glob($path.'/*/') as $folder)
{
	$explode = explode('/', $folder);
	array_pop($explode);
	$name = array_pop($explode);
	$options[$name] = $name;
}

I think this code gets folder names inside a certain folder. Unfortunately this code doesn't seem to work properly in windows because linux uses "/" as directory separator and windows "\"

I've tried to change this code to
PHP:
foreach (glob($path.'/*/') as $folder)
{
	$folder = str_replace('\\','/',$folder);
	$explode = explode('/', $folder);
	array_pop($explode);
	$name = array_pop($explode);
	$options[$name] = $name;
}
Yet I still don't have success in fixing it.

Help is appreciated.
 

1 comment

I managed to fix code :)
PHP:
				// SERVER: Windows or other OS?
				if (strpos(strtolower(php_uname()), 'windows') === FALSE)
				{
					// Linux/Solaris/Mac...
					foreach (glob($path.'/*/') as $folder)
					{
						$explode = explode('/', $folder);
						array_pop($explode);
						$name = array_pop($explode);
						$options[$name] = $name;
					}
				}
				else
				{
					// Windows
					foreach (glob($path.'/*') as $folder)   
					{                     
						if (is_dir($folder))
						{
							$folder .= '/';
						}
						$folder = str_replace('\\','/',$folder);
						$folder = str_replace('//','/',$folder);

						$explode = explode('/', $folder);
						array_pop($explode);
						$name = array_pop($explode);
						$options[$name] = $name;
					}
					array_pop($options);
				}
				// Done :)
 
Status
Not open for further replies.

About the author

NewEraCracker
Active Member · Joined
The Cracker of New Era
1,335
Messages
203
Reactions
63
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom