Image File Upload

Results 1 to 2 of 2

Thread: Image File Upload

  1. #1
    Jon Guest

    Default Image File Upload

    Hi All,<BR>Im having a spot of trouble reading and saving an uploaded image file from a posted multipart form.<BR><BR>I have a basic form as coded below....<BR><BR>&#060;FORM ENCTYPE="multipart/form-data" METHOD=POST ACTION="UpdateStyleImage.asp?RecId=&#060;%= sRecId %&#062;" NAME=DataForm&#062;<BR><BR>Image File : &#060;input type=FILE name=FileName&#062;<BR> &#060;input type=submit value=Upload&#062;<BR> <BR>&#060;/FORM&#062;<BR><BR>Which works okay, but where Im having trouble is saving the file, below is an extract to from the asp page reading the posted form.<BR><BR>sFormSize = Request.TotalBytes<BR>sFormData = Request.BinaryRead(sFormSize)<BR><BR>bnCRLF = chrB(13) & chrB(10)<BR>sDivider = Leftb(sFormData,Instrb(sFormData,bnCRLF) - 1)<BR>sDataStart = Instrb(sFormData, bnCRLF & bnCRLF) + 4<BR>sDataEnd = Instrb(sDataStart + 1, sFormData, sDivider) - sDataStart<BR><BR>&#039;this stuff is just debug, I can output the file in its raw format...<BR>&#039;response.contenttype = "image/gif"<BR>&#039;response.ContentType="text/plain"<BR>&#039;response.binarywrite Midb(sFormData,sDataStart,sDataEnd)<BR>&#039;respo nse.end<BR><BR>dim filesys, demofile, txtstream<BR><BR>set filesys = CreateObject ("Scripting.FileSystemObject")<BR><BR>set demofile = filesys.CreateTextFile (Server.MapPath("cartonstylessomefile.gif"), True)<BR>set demofile = filesys.GetFile(Server.MapPath("cartonstylessomefi le.gif"))<BR><BR>set txtstream = demofile.OpenAsTextStream (2,-1)<BR>txtstream.Write Request.BinaryRead(Request.TotalBytes)<BR>txtstrea m.Close<BR><BR>The file is created but when I open it, it is not recognised as a gif????<BR><BR>Any Ideas

  2. #2
    Join Date
    Dec 1969

    Default RE: Image File Upload

    Here&#039;s is what is going wrong, you are dumping the binary into a file, you need to format it first:<BR><BR><BR>FileData = Request.BinaryRead(Request.TotalBytes)<BR><BR>For nIndex = 1 to LenB(FileData)<BR> oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))<BR>Next<BR><BR> File.close<BR><BR>Hope that helps<BR><BR>Tooze

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts