Blog Kategori:

Merhabalar. ASP sitenizde seçtiğiniz bir klasörden rastgele bir resim göstermek ister misiniz? Bunu aşağıdaki kodlar ile yapabilirsiniz. Burada yapmanız gereken IMGS_DIR yolunu istediğiniz bir klasör olarak belirlemeniz. Sayfanız her yenilendiğinde klasörde bulunan resimlerinizden rastgele bir resim seçilip gösterilecektir.
<% Const IMGS_DIR = "/okulfotolari/"
Dim objFSO, objFolderObject, objFileCollection, objFile
Dim intFileNumberToUse, intFileLooper
Dim objImageFileToUse
Dim strImageSrcText
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolderObject = objFSO.GetFolder(Server.MapPath(IMGS_DIR))
Set objFSO = Nothing
Set objFileCollection = objFolderObject.Files
Set objFolderObject = Nothing
Randomize()
intFileNumberToUse = Int(objFileCollection.Count * Rnd) + 1
intFileLooper = 1
For Each objFile in objFileCollection
If intFileLooper = intFileNumberToUse Then
Set objImageFileToUse = objFile
Exit For
End If
intFileLooper = intFileLooper + 1
Next
Set objFileCollection = Nothing
strImageSrcText = IMGS_DIR & objImageFileToUse.Name
Set objImageFileToUse = Nothing
%>
Yok ben bir değil iki veya daha fazla fotoğrafı rastgele çekmek istiyorsanız bu kodları
<% Const IMGS_DIR2 = "/okulfotolari/"
Dim objFSO2, objFolderObject2, objFileCollection2, objFile2
Dim intFileNumberToUse2, intFileLooper2
Dim objImageFileToUse2
Dim strImageSrcText2
Set objFSO2 = Server.CreateObject("Scripting.FileSystemObject")
Set objFolderObject2 = objFSO2.GetFolder(Server.MapPath(IMGS_DIR2))
Set objFSO2 = Nothing
Set objFileCollection2 = objFolderObject2.Files
Set objFolderObject2 = Nothing
Randomize()
intFileNumberToUse2 = Int(objFileCollection2.Count * Rnd) + 1
intFileLooper2 = 1
For Each objFile2 in objFileCollection2
If intFileLooper2 = intFileNumberToUse2 Then
Set objImageFileToUse2 = objFile2
Exit For
End If
intFileLooper2 = intFileLooper2 + 1
Next
Set objFileCollection2 = Nothing
strImageSrcText2 = IMGS_DIR2 & objImageFileToUse2.Name
Set objImageFileToUse2 = Nothing
%>
şeklinde çoğaltabilirsiniz.