J jonken Medlem sedan mars 2007 4 inlägg Frågan 20 okt. 2008 17:35 #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
J jonken Medlem sedan mars 2007 4 inlägg 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 );
}
?>