Fetstil Fetstil Kursiv Understrykning linje färgläggning tabellverk Punktlista Nummerlista Vänster Centrerat högerställt Utfyllt Länk Bild htmlmode
  • Forum & Blog
    • Forum - översikt
      • .Net
        • asp.net generellt
        • c#
        • vb.net
        • f#
        • silverlight
        • microsoft surface
        • visual studio .net
      • databaser
        • sql-server
        • databaser
        • access
        • mysql
      • mjukvara klient
        • datorer och komponenter
        • nätverk, lan/wan
        • operativsystem
        • programvaror
        • säkerhet, inställningar
        • windows server
        • allmänt
        • crystal reports
        • exchange/outlook
        • microsoft office
      • mjukvara server
        • active directory
        • biztalk
        • exchange
        • linux
        • sharepoint
        • webbservers
        • sql server
      • appar (win/mobil)
      • programspråk
        • c++
        • delphi
        • java
        • quick basic
        • visual basic
      • scripting
        • asp 3.0
        • flash actionscript
        • html css
        • javascript
        • php
        • regular expresssion
        • xml
      • spel och grafik
        • DirectX
        • Spel och grafik
      • ledning
        • Arkitektur
        • Systemutveckling
        • krav och test
        • projektledning
        • ledningsfrågor
      • vb-sektioner
        • activeX
        • windows api
        • elektronik
        • internet
        • komponenter
        • nätverk
        • operativsystem
      • övriga forum
        • arbete karriär
        • erbjuda uppdrag och tjänster
        • juridiska frågor
        • köp och sälj
        • matematik och fysik
        • intern information
        • skrivklåda
        • webb-operatörer
    • Posta inlägg i forumet
    • Chatta med andra
  • Konto
    • Medlemssida
    • Byta lösenord
    • Bli bonsumedlem
    • iMail
  • Material
    • Tips & tricks
    • Artiklar
    • Programarkiv
  • JOBB
  • Student
    • Studentlicenser
  • KONTAKT
    • Om pellesoft
    • Grundare
    • Kontakta oss
    • Annonsering
    • Partners
    • Felanmälan
  • Logga in

Hem / Forum översikt / inlägg

Posta nytt inlägg


upload

Postades av 2002-02-27 23:44:46 - Stefan Bergh, i forum asp - allmänt, Tråden har 1 Kommentarer och lästs av 544 personer

vad är koden för at ladda upp en fil till servern?

alltså bara själva asp-koden som laddar upp filen i en speciell mapp, inget annat trams ;)


Svara

Sv: upload

Postades av 2002-02-28 08:42:13 - Diana Jonsson

Här kommer kod för upload i ASP, det är Microsofts. Denna kod finns även att ladda hem på Microsofts hemsida.

Denna fil heter filePost.asp:
<%
' Adjust this depending on the size
' of the files you will be accepting
server.scripttimeout = 5400

const ForWriting = 2
const TristateTrue = -1
crlf = chr(13) & chr(10)

' This function retreives a field's name
function getFieldName( infoStr)
sPos = inStr( infoStr, "name=")
endPos = inStr( sPos + 6, infoStr, chr(34) & ";")
if endPos = 0 then
endPos = inStr( sPos + 6, infoStr, chr(34))
end if
getFieldName = mid( infoStr, sPos + 6, endPos - (sPos + 6))
end function

' This function retreives a file field's filename
function getFileName( infoStr)
sPos = inStr( infoStr, "filename=")
endPos = inStr( infoStr, chr(34) & crlf)
getFileName = mid( infoStr, sPos + 10, endPos - (sPos + 10))
end function

' This function retreives a file field's mime type
function getFileType( infoStr)
sPos = inStr( infoStr, "Content-Type: ")
getFileType = mid( infoStr, sPos + 14)
end function

' Yank the file (and anything else) that was posted
postData = ""
Dim biData
biData = Request.BinaryRead(Request.TotalBytes)
' Careful! It's binary! So, let's change
' it into something a bit more manageable
for nIndex = 1 to LenB( biData)
postData = postData & Chr(AscB(MidB( biData, nIndex, 1)))
next

' Having used BinaryRead, the Request.Form collection is no longer
' available to us. So, we have to parse the request variables ourselves!
' First, let's find that encoding type!
contentType = Request.ServerVariables( "HTTP_CONTENT_TYPE")
ctArray = split( contentType, ";")
' file posts only work well when the encoding is
' "multipart/form-data", so let's check for that!
if trim(ctArray(0)) = "multipart/form-data" then
errMsg = ""
' grab the form boundry...
bArray = split( trim( ctArray(1)), "=")
boundry = trim( bArray(1))
' now use that to split up all the variables!
formData = split( postData, boundry)
' now, we need to extract the information for each variable and it's data
dim myRequest, myRequestFiles(9, 3)
Set myRequest = CreateObject("Scripting.Dictionary")
'Set myRequestFiles = CreateObject("Scripting.Dictionary")
fileCount = 0
for x = 0 to ubound( formData)
' two sets of crlf mark the end of the information about this field
' everything after that is the value
infoEnd = instr( formData(x), crlf & crlf)
if infoEnd > 0 then
' pull the info for this field, minus the stuff at the ends...
varInfo = mid( formData(x), 3, infoEnd - 3)
' pull the value for this field, being sure to
' skip the crlf pairs at the start and the crlf-- at the end
varValue = mid( formData(x), infoEnd + 4, len(formData(x)) - infoEnd - 7)
' now, is this a file?
if (instr( varInfo, "filename=") > 0) then
' place it into our files array
' While this supports more than one file uploaded at a time
' we only consider the single file case in this example
myRequestFiles( fileCount, 0) = getFieldName( varInfo)
myRequestFiles( fileCount, 1) = varValue
myRequestFiles( fileCount, 2) = getFileName( varInfo)
myRequestFiles( fileCount, 3) = getFileType( varInfo)
fileCount = fileCount + 1
else
' it's a regular field
myRequest.add getFieldName( varInfo), varValue
end if
end if
next
else
errMsg = "Wrong encoding type!"
end if

' save the actual posted file
' if you are supporting more than one file, just turn this into a loop!
set lf = server.createObject( "Scripting.FileSystemObject")
if myRequest("filename") = "original" then
' Use the file name that came with the file
' at this point, you need to determine what sort of client sent the file
' Mac's only send the file name, with no path information, while Windows
' clients send the entire path of the file that was selected
browserType = UCase( Request.ServerVariables( "HTTP_USER_AGENT"))
if (inStr(browserType, "WIN") > 0) then
' it's Windows... yank the filename off the end!
sPos = inStrRev( myRequestFiles( 0, 2), "\")
fName = mid( myRequestFiles( 0, 2), sPos + 1)
end if
if (inStr(browserType, "MAC") > 0) then
' it's a Mac. Simple.
' Of course, Mac file names can contain characters that are
' illegal under Windows, so you need to look out for that!
fName = myRequestFiles(0, 2)
end if
' If your upload path is different, set that here
filePath = "./" & fName
else
' use the user-specified file name instead
' If your upload path is different, set that here
filePath = "./" & myRequest("userSpecifiedName")
end if
savePath = server.mapPath( filePath)
set saveFile = lf.createtextfile(savePath, true)
saveFile.write( myRequestFiles(0, 1))
saveFile.close

' IIS tends to hang if you don't explicitly return SOMETHING.
' So, you should redirect to another page or simply thank them right here...
%>
<html>
<body>
<% if errMsg = "" then %>
Thanks for the file! It was yummy!
<%else %>
<%= errMsg %>
<% end if %>
</body>
</html>



Denna kodsnutt läggs i en annan fil för att anropa fil ovan:
<form action="filePost.asp" enctype="multipart/form-data" method="post" name="f" id="f" class="text1">
Välj vilken fil du vill ladda upp till servern
<br>
<input type="file" name="test" size="50">

<br></br>

<input type="radio" name="filename" value="original" checked>
Använd ursrungligt filnamn

<br></br>

<input type="radio" name="filename" value="userSpecified">
Byt filnamn till:

<input type="text" name="userSpecifiedName" value="" size="25">

<br></br>

<table>
<tr>
<td>
<INPUT type="submit" value=" Ladda upp " id=isave name=nsave>
</td>
</form>


Hoppas det kommer funka.
/Diana


Svara

Nyligen

  • 14:16 Indian online casino
  • 14:15 Indian online casino
  • 08:28 Butiksskyltar: Hur upplever utbude
  • 22:31 Slappna av
  • 19:55 kick-off med fokus på hälsa?
  • 19:53 kick-off med fokus på hälsa?
  • 16:24 Föreslå en skönhetsklinik online
  • 16:23 Föreslå en skönhetsklinik online

Sidor

  • Hem
  • Bli bonusmedlem
  • Läs artiklar
  • Chatta med andra
  • Sök och erbjud jobb
  • Kontakta oss
  • Studentlicenser
  • Skriv en artikel

Statistik

Antal besökare:
Antal medlemmar:
Antal inlägg:
Online:
På chatten:
4 570 843
27 961
271 763
765
0

Kontakta oss

Frågor runt konsultation, rådgivning, uppdrag, rekrytering, annonsering och övriga ärenden. Ring: 0730-88 22 24 | pelle@pellesoft.se

© 1986-2013 PelleSoft AB. Last Build 4.1.7169.18070 (2019-08-18 10:02:21) 4.0.30319.42000
  • Om
  • Kontakta
  • Regler
  • Cookies