webForumDet fria alternativet

åäö med readdir i bildgalleri

PHP

1 svar · 350 visningar · startad av jonken

Medlem sedan mars 20074 inlägg
Frågan#1

Hej.

Sitter och gör ett jobb åt min gamla skola.

I bildgalleriet har jag gjort så att PHP ska läsa av diret bilder/ och leta upp kataloger och sedan spotta ut en länk med varje katalog som bildsektion.

http://www.skattungbyn.mora.fhsk.se/?page=bilder

Till problemet:
När jag har kataloger med åäö i så vill den inte länka rätt, även om den hittar rätt antal bilder och liknande. Det är någonstans i själva länkning det inte blir rätt. Så då tänkte jag att man kunde avnända urlencode() för att lösa detta. Vips, det funkar. Men då lägger den istället till ett + istället för mellanslag på de kataloger med mellanslag i katalogen, vilket gör att det länkar fel där istället.

Är relativt ny på PHP och har ingen aning om hur jag ska lösa detta.

Någon som har något tips?

här är koden...

<?

	if( isset( $_GET['album'] ) ) {	
		
				$allowedFileExtensions = array(
			'jpg',
			'png',
			'gif'
		);
		
	    if( $handle = @opendir( 'bilder/' . $_GET['album'] ) ) {
	        while( false !== ( $foundSomethingAgain = readdir( $handle ) ) ) {
	            if( $foundSomethingAgain != '.' && $foundSomethingAgain != '..' ) {
	                if( is_file( 'bilder/' . $_GET['album']. '/' . $foundSomethingAgain ) ) {
						$foundExtension = explode( '.', $foundSomethingAgain );
						$foundExtension = $foundExtension[ sizeof( $foundExtension ) -1 ];
						$foundExtension = strtolower( $foundExtension );
						if( in_array( $foundExtension, $allowedFileExtensions ) ) {
							echo '<a href="bilder/' . urlencode($_GET['album']). '/' . $foundSomethingAgain . '" rel="lightbox" title="'.$_GET['album'].'">
					<img src="bilder/' . urlencode($_GET['album']). '/' . $foundSomethingAgain . '" border="1" width="20%" height="20%" style="margin:5px;"></a>';
						}
	                }
	            }
	        }
	        }
	        closedir( $handle );
	    }
?>

Supertacksam för hjälpen!

Mvh
Jonas

Medlem sedan mars 20074 inlägg
#2

löste det nu med hjälp av

<?

	if( isset( $_GET['album'] ) ) {	
		
				$allowedFileExtensions = array(
			'jpg',
			'png',
			'gif'
		);
		
	    if( $handle = @opendir( 'bilder/' .[B] str_replace("+", " ",[/B] $_GET['album']) ) ) {
	        while( false !== ( $foundSomethingAgain = readdir( $handle ) ) ) {
	            if( $foundSomethingAgain != '.' && $foundSomethingAgain != '..' ) {
	                if( is_file( 'bilder/' . $_GET['album']. '/' . $foundSomethingAgain ) ) {
						$foundExtension = explode( '.', $foundSomethingAgain );
						$foundExtension = $foundExtension[ sizeof( $foundExtension ) -1 ];
						$foundExtension = strtolower( $foundExtension );
						if( in_array( $foundExtension, $allowedFileExtensions ) ) { 
							echo '<a href="bilder/' . str_replace("+", " ", urlencode($_GET['album'])). '/' . $foundSomethingAgain . '" rel="lightbox" title="'.$_GET['album'].'">
					<img src="bilder/' . str_replace("+", " ", urlencode($_GET['album'])). '/' . $foundSomethingAgain . '" border="1" width="20%" height="20%" style="margin:5px;"></a>';
						}
	                }
	            }
	        }
	        }
	        closedir( $handle );
	    }
?>
288 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
126 ms — deklarationer (db)
0 ms — hämta statistik (cache)
157 ms — hämta tråd, inlägg och bilagor (db)
128 ms — ändringar (db)