I am currently writing an web upload client and I have run into a problem and need some help. The basic client works with text files no problem. But when I try word files (.doc) I only get about 6 bytes of the file. This due to the fact that there is (1A character) End of file marker in the header of the file.
The problem is in STDIN LINE Temp, it does not handle binary files. It stops
reading at the End of file marker.
What I need is a way to read binary files from stdin that ignores the end of file marker.
This is the code
'------------------------------------------------------------------
' This the web based document manager version 1.0
' by M C Draper Advanced Business Concepts
'
' Changes 14/3/2009 Initial Version
'------------------------------------------------------------------
#COMPILE EXE
#DIM ALL
$INCLUDE "\pbcc40\file.inc"
$INCLUDE "\pbcc40\PBCGI.INC"
$INCLUDE "\pbcc40\CGIlib.inc"
SUB LoadPage(HtmlPage AS STRING)
'
' thie routine will check if the files exits, then open and read the file
' and output throught cgi to the client
'
DIM filehandle AS LONG
DIM Buffer AS STRING
'
IF FileExists(HtmlPage) = 0 THEN EXIT SUB
'
' Open the file
Filehandle = FREEFILE
OPEN Htmlpage FOR INPUT AS Filehandle
'
' read the contents of the file
WHILE NOT EOF(FileHandle)
LINE INPUT# Filehandle, Buffer
WriteCGI buffer
WEND
CLOSE FileHandle
END SUB
SUB ListFiles
LoadPage("menupage.html")
END SUB
SUB UploadFile
ON ERROR RESUME NEXT
LOCAL Temp AS STRING
LOCAL Buffer AS STRING
LOCAL Boundary AS STRING
LOCAL Content AS STRING
LOCAL Context AS STRING
LOCAL Filename AS STRING
LOCAL FileNameStart AS INTEGER
LOCAL File AS STRING
LOCAL Filehandle AS LONG
STDIN LINE Boundary
writecgi "Boundary = "+Boundary + "<br>"
STDIN LINE Content
writecgi "Content = "+Content + "<br>"
STDIN LINE Context
writecgi "Context = "+Context + "<br>"
Buffer = ""
WHILE INSTR(Temp,Boundary) = 0
STDIN LINE Temp
'
' don't add the boundaty to the file
IF INSTR(Temp,Boundary) = 0 THEN Buffer = Buffer + Temp + $CRLF
'writecgi temp
WEND
writecgi "File = " + Buffer + "<br>"
FileNameStart = INSTR(Content,"filename=") + 10
FileName = MID$(Content,FileNameStart,LEN(Content) - FileNameStart)
writecgi Filename
File = RIGHT$(Filename,LEN(filename) - INSTR(-1,Filename,"\"))
writecgi ">"+file+"<"
'
'
' Save the file to disk
' You cam savein the web directory as it is write protected. You havew to a separte directory
' for the uploaded files.
'
Filehandle = FREEFILE
OPEN "c:\" +File FOR OUTPUT AS Filehandle
PRINT# Filehandle, Buffer
CLOSE Filehandle
writecgi "error = " + STR$(ERR)
END SUB
FUNCTION PBMAIN () AS LONG
DIM UserLine AS STRING
IF COMMAND$ = "ListFiles" THEN ListFiles:EXIT FUNCTION
IF COMMAND$ = "UploadFile" THEN UploadFile:EXIT FUNCTION
END FUNCTION
The problem is in STDIN LINE Temp, it does not handle binary files. It stops
reading at the End of file marker.
What I need is a way to read binary files from stdin that ignores the end of file marker.
This is the code
'------------------------------------------------------------------
' This the web based document manager version 1.0
' by M C Draper Advanced Business Concepts
'
' Changes 14/3/2009 Initial Version
'------------------------------------------------------------------
#COMPILE EXE
#DIM ALL
$INCLUDE "\pbcc40\file.inc"
$INCLUDE "\pbcc40\PBCGI.INC"
$INCLUDE "\pbcc40\CGIlib.inc"
SUB LoadPage(HtmlPage AS STRING)
'
' thie routine will check if the files exits, then open and read the file
' and output throught cgi to the client
'
DIM filehandle AS LONG
DIM Buffer AS STRING
'
IF FileExists(HtmlPage) = 0 THEN EXIT SUB
'
' Open the file
Filehandle = FREEFILE
OPEN Htmlpage FOR INPUT AS Filehandle
'
' read the contents of the file
WHILE NOT EOF(FileHandle)
LINE INPUT# Filehandle, Buffer
WriteCGI buffer
WEND
CLOSE FileHandle
END SUB
SUB ListFiles
LoadPage("menupage.html")
END SUB
SUB UploadFile
ON ERROR RESUME NEXT
LOCAL Temp AS STRING
LOCAL Buffer AS STRING
LOCAL Boundary AS STRING
LOCAL Content AS STRING
LOCAL Context AS STRING
LOCAL Filename AS STRING
LOCAL FileNameStart AS INTEGER
LOCAL File AS STRING
LOCAL Filehandle AS LONG
STDIN LINE Boundary
writecgi "Boundary = "+Boundary + "<br>"
STDIN LINE Content
writecgi "Content = "+Content + "<br>"
STDIN LINE Context
writecgi "Context = "+Context + "<br>"
Buffer = ""
WHILE INSTR(Temp,Boundary) = 0
STDIN LINE Temp
'
' don't add the boundaty to the file
IF INSTR(Temp,Boundary) = 0 THEN Buffer = Buffer + Temp + $CRLF
'writecgi temp
WEND
writecgi "File = " + Buffer + "<br>"
FileNameStart = INSTR(Content,"filename=") + 10
FileName = MID$(Content,FileNameStart,LEN(Content) - FileNameStart)
writecgi Filename
File = RIGHT$(Filename,LEN(filename) - INSTR(-1,Filename,"\"))
writecgi ">"+file+"<"
'
'
' Save the file to disk
' You cam savein the web directory as it is write protected. You havew to a separte directory
' for the uploaded files.
'
Filehandle = FREEFILE
OPEN "c:\" +File FOR OUTPUT AS Filehandle
PRINT# Filehandle, Buffer
CLOSE Filehandle
writecgi "error = " + STR$(ERR)
END SUB
FUNCTION PBMAIN () AS LONG
DIM UserLine AS STRING
IF COMMAND$ = "ListFiles" THEN ListFiles:EXIT FUNCTION
IF COMMAND$ = "UploadFile" THEN UploadFile:EXIT FUNCTION
END FUNCTION
Comment