Fso ile upload

bLoOdLusT1912

Kadim Üye
1 Ağu 2007
5,470
41
Kod:
[FONT=Tahoma][SIZE=3][COLOR=white]Web alanımıza her ne kadar sadece biz ftp ile dosya yüklüyorsak ta bazen kullanıcıdan dosya almamız yada yaptığımız uygulama gereği web üzerinden dosya yüklememiz gerekiyor. Mesela sitenizin yönetim bölümünde haber eklediğinizde habere ait birde resim yüklemek isteyebilirsiniz. Eğer kendi bilgisayarınız yada ftp kurulu bir bilgisayarda iseniz ftp ile bu resmi yükleyebilirsiniz. Ancak bu hem zaman kaybı gereksiz bir işlem olur. Bu durumda yardımımıza Upload komponentleri yetişir. Peki kullandığınız server herhangi bir komponent kullanmanıza izin vermiyorsa. İşte bu durumda da yardımımıza ASP'nin File System Object nesnesi yetişiyor. Aşağıdaki kodlarla serverinizde hiçbir upload komponenti olmasa bile dosya yükleyebilirsiniz. Ancak tabiki yüklenecek klasöre yazma izni verilmiş olmalı. Yoksa hata alırsınız.[/COLOR][/SIZE][/FONT]
 
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]Dosya seçeceğimiz sayfa. İsmi önemli değil.[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]------------ UploadForm.htm----------------[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]<FORM METHOD="Post" ENCTYPE="multipart/form-data" ACTION="Upload.asp">[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Dosya:<INPUT NAME="dosya" TYPE="file" size="25"><BR>[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]<INPUT TYPE="submit" Value="Kaydet">[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]</FORM>[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]------------[/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]Ve bu formdan dosyayı alıp servera yükleyecek Upload.asp sayfamız. Bu kod üzerinde sadece 5.satırda Yol isimli değişkende yüklenecek klasörü belirleyin. Sondaki \ işaretini ise kaldırmayın.[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]-----------Upload.asp--------[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]<%[/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Set Yukle = New DosyaYukleme[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]Yol = Server.Mappath("dosyalar")&"\"[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]DosyaIsmi = Yukle.FileName (" dosya ")[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]Set FSO = Server.CreateObject("Scripting.FileSystemObject>" )[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]Set YeniDosya = FSO.CreateTextFile(Yol & DosyaIsmi)[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]For i = 1 To LenB(Yukle.Value("dosya" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]  YeniDosya.Write Chr(AscB(MidB(Yukle.Value("dosya" ), i, 1))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Next [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]YeniDosya.Close [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Set YeniDosya = Nothing [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Set FSO = Nothing [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]Set Yukle = Nothing [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]%> [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Yüklendi.[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]<!-- ***** Bu bölümden aşağısını değiştirmeyin **** -->[/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]<% [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]Class DosyaYukleme [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Private pvObjUploadRequest [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Private Sub Class_Initialize [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim RequestBin, Boundary, Value [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim lngPosBegin, lngPosEnd, lngBoundaryPos [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim lngPos, lngPosFile, lngPosBound [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim strName, strFileName, strContentType [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim objUploadControl [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]         Set pvObjUploadRequest = Server.CreateObject("Scripting.Dictionary" ) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]         RequestBin = Request.BinaryRead(Request.TotalBytes) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]         lngPosBegin = 1 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         lngPosEnd = InStrB(lngPosBegin, RequestBin, GetByteString(Chr(13))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Boundary = MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         lngBoundaryPos = InstrB(1, RequestBin, Boundary) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]         Do Until (lngBoundaryPos = InstrB(RequestBin, Boundary & getByteString("--" ))) [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]              Set objUploadControl = CreateObject("Scripting.Dictionary" ) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPos = InstrB(lngBoundaryPos, RequestBin, GetByteString("Content-Disposition" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPos = InstrB(lngPos, RequestBin, GetByteString("name=" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPosBegin = lngPos + 6 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPosEnd = InstrB(lngPosBegin, RequestBin, GetByteString(Chr(34))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              strName = LCase(GetString(MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPosFile = InstrB(lngBoundaryPos, RequestBin, GetByteString("filename=" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              lngPosBound = InstrB(lngPosEnd, RequestBin, Boundary) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]              If lngPosFile <> 0 AND lngPosFile < lngPosBound Then [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosBegin = lngPosFile + 10 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosEnd = InStrB(lngPosBegin, RequestBin, GetByteString(Chr(34))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   strFileName = GetString(MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin)) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]                   objUploadControl.Add "FileName" , strFileName [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPos = InStrB(lngPosEnd, RequestBin, GetByteString("Content-Type:" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosBegin = lngPos + 14 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosEnd = InStrB(lngPosBegin, RequestBin, GetByteString(Chr(13))) [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]                   strContentType = GetString(MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin)) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   objUploadControl.Add "ContentType" , strContentType [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosBegin = lngPosEnd + 4 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosEnd = InstrB(lngPosBegin, RequestBin, Boundary) - 2 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   Value = MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Else [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPos = InstrB(lngPos, RequestBin, GetByteString(Chr(13))) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosBegin = lngPos + 4 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   lngPosEnd = InStrB(lngPosBegin, RequestBin, Boundary) - 2 [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   Value = GetString(MidB(RequestBin, lngPosBegin, lngPosEnd - lngPosBegin)) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              End If [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]              objUploadControl.Add "Value" , Value      [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]              pvObjUploadRequest.Add strName, objUploadControl [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]              lngBoundaryPos = InStrB(lngBoundaryPos + LenB(Boundary), RequestBin, Boundary) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Loop [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Sub [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Private Sub Class_TerMINate [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim objDictionary [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]         For Each objDictionary In pvObjUploadRequest.Items [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              objDictionary.RemoveAll [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Set objDictionary = Nothing [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Next [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         pvObjUploadRequest.RemoveAll [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Set pvObjUploadRequest = Nothing [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Sub [/COLOR][/FONT][/SIZE]
 
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Private Function GetByteString(strString) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim Char [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim i [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]         For i = 1 To Len(strString) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]               Char = Mid(strString, i , 1) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              GetByteString = GetByteString & ChrB(AscB(Char)) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Next [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Private Function GetString(strBin) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim intCount [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]         GetString = "" [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]         For intCount = 1 To LenB(strBin) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              GetString = GetString & Chr(AscB(MidB(strBin, intCount, 1)))  [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Next [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Public Function Value(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Name = LCase(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         If pvObjUploadRequest.Exists(Name) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Value = pvObjUploadRequest.Item(Name).Item("Value" ) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Value = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Public Function ContentType(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Name = LCase(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         If pvObjUploadRequest.Exists(Name) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              If pvObjUploadRequest.Item(Name).Exists("ContentType" ) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   ContentType = pvObjUploadRequest.Item(Name).Item("ContentType" ) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   ContentType = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              ContentType = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Public Function FileNamePath(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Name = LCase(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         If pvObjUploadRequest.Exists(Name) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              If pvObjUploadRequest.Item(Name).Exists("FileName" ) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   FileNamePath = pvObjUploadRequest.Item(Name).Item("FileName" ) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   FileNamePath = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              FileNamePath = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
 
[SIZE=3][FONT=Tahoma][COLOR=white]    Public Function FileName(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Dim strFileName [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]         Name = LCase(Name) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         If pvObjUploadRequest.Exists(Name) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              If pvObjUploadRequest.Item(Name).Exists("FileName" ) Then [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   strFileName = pvObjUploadRequest.Item(Name).Item("FileName" ) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   FileName = Right(strFileName, Len(strFileName) - InStrRev(strFileName, "\" )) [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]                   FileName = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         Else [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]              FileName = Empty [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]         End If [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]    End Function [/COLOR][/FONT][/SIZE]
 
[SIZE=3][FONT=Tahoma][COLOR=white]End Class [/COLOR][/FONT][/SIZE]
[SIZE=3][FONT=Tahoma][COLOR=white]%>[/COLOR][/FONT][/SIZE]
 
Üst

Turkhackteam.org internet sitesi 5651 sayılı kanun’un 2. maddesinin 1. fıkrasının m) bendi ile aynı kanunun 5. maddesi kapsamında "Yer Sağlayıcı" konumundadır. İçerikler ön onay olmaksızın tamamen kullanıcılar tarafından oluşturulmaktadır. Turkhackteam.org; Yer sağlayıcı olarak, kullanıcılar tarafından oluşturulan içeriği ya da hukuka aykırı paylaşımı kontrol etmekle ya da araştırmakla yükümlü değildir. Türkhackteam saldırı timleri Türk sitelerine hiçbir zararlı faaliyette bulunmaz. Türkhackteam üyelerinin yaptığı bireysel hack faaliyetlerinden Türkhackteam sorumlu değildir. Sitelerinize Türkhackteam ismi kullanılarak hack faaliyetinde bulunulursa, site-sunucu erişim loglarından bu faaliyeti gerçekleştiren ip adresini tespit edip diğer kanıtlarla birlikte savcılığa suç duyurusunda bulununuz.