Passage du nom d'un fichier en argument
Bonjour,
Je cherche a recuperer le nom d'une photo contenue dans un dossier comme argument d'une fonction Javascript.
Cependant la fonction ne s'execute pas lors de mes diverses tentatives. Je demande donc un peu d'aide :)
Voici mon code:
Code PHP:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<?php
$i=0;
if ($handle = opendir('diaporama/')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$photos[]=$file;
}
}
closedir($handle);
}
$taille=count($photos);
$derniere= $photos[$taille-1];
echo $derniere;
?>
<div>
<table id="diaporama">
<tr>
<td>
<a href="javascript:chgt_photo(1)" onmouseover="javascript:flag(1)" onmouseout="javascript:flag(3)" ><img id="prec"src="fleche1.png"></img></a>
</td>
<td>
<a href=# ><img id="photo_diapo" onLoad="javascript:verif(<?php echo $derniere; ?>)" src="diaporama/1.png" WIDTH=400 HEIGHT=300></a>
</td>
<td>
<a href="javascript:chgt_photo(2)" onmouseover="javascript:flag(2)" onmouseout="javascript:flag(4)">
<img id="suiv" src="fleche2.png"></img>
</a>
</td>
<tr>
</table>
</div> |
code JS:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
function flag(type){
if( type == 1 ){//si la variable reçu vaut 1
//Suppression de l'ancien contenu
document.getElementById("prec").src ="fleche_prec.png";
}
else if( type == 2 ){//si la variable reçu vaut 2
//Suppression de l'ancien contenu
document.getElementById("suiv").src ="fleche_suiv.png";
}
else if( type == 3 ){//si la variable reçu vaut 2
//Suppression de l'ancien contenu
document.getElementById("prec").src ="fleche1.png";
}
else if( type == 4 ){//si la variable reçu vaut 2
//Suppression de l'ancien contenu
document.getElementById("suiv").src ="fleche2.png";
}
}
function chgt_photo(type, derniere){
var nom= document.getElementById("photo_diapo").getAttribute("src");
var nom_entier= nom.split('.')[0];
alert(derniere);
var nom_decompose=nom_entier.split('/');
var base=nom_decompose[0];
var entier=nom_decompose[1];
var ext = nom.split('.')[1];
if (type == 1){var nvx_ent= parseInt(entier) -1;}
if (type == 2){var nvx_ent= parseInt(entier) +1;}
var nvx_ent = nvx_ent.toString();
//alert(nvx_nom + '.' + ext);
document.getElementById("photo_diapo").src = base + '/' + nvx_ent + '.' + ext ;
if (nvx_ent + '.' + ext == derniere){
alert('Derniere photo');
}
//document.getElementByID("photo_diapo").src
}
function verif(derniere){
alert(derniere);
} |