النتائج 1 إلى 2 من 2

الموضوع: سكربت ASP للتحميل في الموقع

  1. #1


    انسخ الكود وسميه مثلا Upload.asp وضعه في الموقع لتتمكن من تحميل أي ملف مباشرة دون استخدام FTP
    يصلح لتحميل الصور وغيرها مع الانتباه لاضافة ضوابط الحماية والصلاحيات المناسبة للوصول
    كود:
        <%response.buffer=true
        Func = Request("Func")
        if isempty(Func) Then
        	Func = 1
        End if
        Select Case Func
        Case 1
        'You do not need to use this form to sen
        '     d your files.
        'However you should not give your submit
        '     button a NAME or ID.	
        %>
        <html dir="rtl">
        <H2>فضلا قم باختيار الصور لتحميلها</H1>
        	<FORM ENCTYPE="multipart/form-data" ACTION="upd.asp?func=2" METHOD=POST id=form1 name=form1>
        	<TABLE>
        		<TR><TD>اضغط(استعراض ) لاختيار الصورة من جهازك<BR></TD></TR>
        		<TR><TD>ثم اضغط ( تحميل )<BR><BR></TD></TR>
        		<TR><TD><STRONG>اسم الملف</STRONG></TD></TR>
        		<TR><TD><INPUT NAME=File1 SIZE=30 TYPE=file><BR></TD></TR>
        		<TR><TD><INPUT NAME=File2 SIZE=30 TYPE=file><BR></TD></TR>
        		<TR><TD><INPUT NAME=File2 SIZE=30 TYPE=file><BR></TD></TR>
        		<TR><TD align=right><INPUT type="submit" value="تحميل"><BR><BR></TD></TR>
        	</TABLE>
        <%
        Case 2
        ForWriting = 2
        	adLongVarChar = 201
        	lngNumberUploaded = 0
        	
        'Get binary data from form		
        	noBytes = Request.TotalBytes 
        	binData = Request.BinaryRead (noBytes)
        'convery the binary data to a string
        	Set RST = CreateObject("ADODB.Recordset")
        	LenBinary = LenB(binData)
        	
        	if LenBinary > 0 Then
        		RST.Fields.Append "myBinary", adLongVarChar, LenBinary
        		RST.Open
        			RST.AddNew
        				RST("myBinary").AppendChunk BinData
        			RST.Update
        		strDataWhole = RST("myBinary")
        	End if
        'Creates a raw data file for with all da
        '     ta sent. Uncomment for debuging.	
        	'Set fso = CreateObject("Scripting.FileSystemObject")
        	'Set f = fso.OpenTextFile(server.mappath(".") & "\raw.txt", ForWriting, True)
        	'f.Write strDataWhole
        	'set f = nothing
        	'set fso = nothing
        'get the boundry indicator
        strBoundry = Request.ServerVariables ("HTTP_CONTENT_TYPE")
        lngBoundryPos = instr(1,strBoundry,"boundary=") + 8 
        strBoundry = "--" & right(strBoundry,len(strBoundry)-lngBoundryPos)
        'Get first file boundry positions.
        lngCurrentBegin = instr(1,strDataWhole,strBoundry)
        lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
        Do While lngCurrentEnd > 0
        'Get the data between current boundry an
        '     d remove it from the whole.
        strData = mid(strDataWhole,lngCurrentBegin, lngCurrentEnd - lngCurrentBegin)
        strDataWhole = replace(strDataWhole,strData,"")
        			
        'Get the full path of the current file.
        	lngBeginFileName = instr(1,strdata,"filename=") + 10
        	lngEndFileName = instr(lngBeginFileName,strData,chr(34)) 
        'Make sure they selected at least one fi
        '     le.	
        	if lngBeginFileName = lngEndFileName and lngNumberUploaded = 0 Then
        	
        			Response.Write "<H2> The following Error occured.</H2>"
        			Response.Write "You must Select at least one file To upload"
        			Response.Write "<BR><BR>Hit the back button, make the needed corrections and resubmit your information."
        			Response.Write "<BR><BR><INPUT type='button' onclick='history.go(-1)' value='<< Back' id='button'1 name='button'1>"
        			Response.End 
        	End if
        'There could be one or more empty file b
        '     oxes.	
        	if lngBeginFileName <> lngEndFileName Then
        		strFilename = mid(strData,lngBeginFileName,lngEndFileName - lngBeginFileName)
        'Creates a raw data file with data betwe
        '     en current boundrys. Uncomment for debug
        '     ing.	
        	'Set fso = CreateObject("Scripting.FileSystemObject")
        	'Set f = fso.OpenTextFile(server.mappath(".") & "\raw_" & lngNumberUploaded & ".txt", ForWriting, True)
        	'f.Write strData
        	'set f = nothing
        	'set fso = nothing
        		
        'Loose the path information and keep jus
        '     t the file name.	
        		tmpLng = instr(1,strFilename,"\")
        		Do While tmpLng > 0
        			PrevPos = tmpLng
        			tmpLng = instr(PrevPos + 1,strFilename,"\")
        		Loop
        		
        		FileName = right(strFilename,len(strFileName) - PrevPos)
        	
        'Get the begining position of the file d
        '     ata sent.
        'if the file type is registered with the
        '     browser then there will be a Content-Typ
        '     e
        		lngCT = instr(1,strData,"Content-Type:")
        	
        		if lngCT > 0 Then
        			lngBeginPos = instr(lngCT,strData,chr(13) & chr(10)) + 4
        		Else
        			lngBeginPos = lngEndFileName
        		End if
        'Get the ending position of the file dat
        '     a sent.
        		lngEndPos = len(strData) 
        		
        'Calculate the file size.	
        		lngDataLenth = lngEndPos - lngBeginPos
        'Get the file data	
        		strFileData = mid(strData,lngBeginPos,lngDataLenth)
        'Create the file.	
        		Set fso = CreateObject("Scripting.FileSystemObject")
        		Set f = fso.OpenTextFile(server.mappath(".") & "\" & FileName, ForWriting, True)
        		f.Write strFileData
        		Set f = nothing
        		Set fso = nothing
        	
        		lngNumberUploaded = lngNumberUploaded + 1
        	
        	End if
        		
        'Get then next boundry postitions if any
        '     .
        	lngCurrentBegin = instr(1,strDataWhole,strBoundry)
        	lngCurrentEnd = instr(lngCurrentBegin + 1,strDataWhole,strBoundry) - 1
        loop
        	
        		Response.Write "<html dir='rtl'> "
    
        		Response.Write "<H2>تم تحميل الملفات</H2>"
        		Response.Write lngNumberUploaded & " ملفات .. تم تحميلها.<BR>"
        		Response.Write "<BR><BR><INPUT type='button' onclick='document.location=" & chr(34) & "upd.asp" & chr(34) & "' value='<< عودة إلى القائمة' id='button'1 name='button'1>"	 						
        	
        End Select	
        %>
        </BODY>
        </HTML>






    ابوصالح غير متواجد حالياً


  2. #2
    عضو نشيط
    تاريخ التسجيل
    May 2001
    المشاركات
    66


    الاخ العزيز ابو صالح ......
    تراني ما دققت في الكود بس لو تشرحة اكون لك من الشاكرين






    aspphp غير متواجد حالياً





ضوابط المشاركة

  • لا تستطيع إضافة مواضيع جديدة
  • لا تستطيع الرد على المواضيع
  • لا تستطيع إرفاق ملفات
  • لا تستطيع تعديل مشاركاتك
  •  

أضف موقعك هنا| اخبار السيارات | حراج | شقق للايجار في الكويت | بيوت للبيع في الكويت | دليل الكويت العقاري | مقروء | شركة كشف تسربات المياه | شركة عزل اسطح بالرياض | عزل فوم بالرياض| عزل اسطح بالرياض | كشف تسربات المياة بالرياض | شركة عزل اسطح بالرياض