Recherche si fichier image existe

pichoro Messages postés 7 Date d'inscription jeudi 26 septembre 2002 Statut Membre Dernière intervention 13 mars 2003 - 26 sept. 2002 à 22:19
hanhod Messages postés 27 Date d'inscription jeudi 19 septembre 2002 Statut Membre Dernière intervention 23 février 2004 - 27 sept. 2002 à 14:03
Bonjour, je recherche un script ASp permettant de verifier si une image appellée x.jpg se trouve bien dans un repertoire "images", si cette image existe je l'affiche sinon c'est une image par defaut que j'affiche.

Merci d'avance

1 réponse

hanhod Messages postés 27 Date d'inscription jeudi 19 septembre 2002 Statut Membre Dernière intervention 23 février 2004
27 sept. 2002 à 14:03
Salam,
Ce code suivant permit de chercher un mot ds un fichier. Vous pouvez vous baser sur, pour chercher le nom d'un fichier :

<HTML>
Search Results for <%=Request("SearchText")%>

<%
Const fsoForReading = 1

Dim strSearchText
strSearchText = Request("SearchText")

'Now, we want to search all of the files
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim objFolder
Set objFolder = objFSO.GetFolder(Server.MapPath("/"))

Dim objFile, objTextStream, strFileContents, bolFileFound
bolFileFound = False

For Each objFile in objFolder.Files
If Response.IsClientConnected then
Set objTextStream = objFSO.OpenTextFile(objFile.Path,fsoForReading)

strFileContents = objTextStream.ReadAll

If InStr(1,strFileContents,strSearchText,1) then
Response.Write "<LI>[ " & objFile.Name & "]
"

bolFileFound = True
End If

objTextStream.Close
End If
Next

if Not bolFileFound then Response.Write "No matches found..."

Set objTextStream = Nothing
Set objFolder = Nothing
Set objFSO = Nothing
%>
</HTML>

Au lieu d'ouvrir le fichier pour le lire, vous pouvez tester sur le nom du fichier.

A vous de jouer
Bonne chance

HN
0
Rejoignez-nous