My users routinely upload files of type *.txt, *.doc and *.pdf, using code based on the sample in the Alpha documentation (http://wiki.alphasoftware.com/Upload...ghlight=upload).
But this method fails for *.docx files. The uploaded file can not be opened by ms word and can not be processed by some file conversion programs like Doxillion (word to pdf converter). After several hours I found the problem and the solution is simple but not obvious so others might find it useful. The upload process using, enctype="multipart/form-data", always adds one null byte to the end of the upload so the file saved is one byte longer than the original. This extra null byte does not seem to make any difference for some file types but makes *.docx files unusable. The simple solution is to remove the last byte before the uploaded data is saved as a file.
The one additional line of code is: FileToUpload.data.RESIZE(FileToUpload.data.SIZE()-1) 'del last byte, always added in upload
I have not seen this effect on file validity mentioned before and it may affect other file types also.
Thanks for reading and for all the helpful information I have found on this board.
Irwin
Code:
<html> <%a5 dim msg as c = "" if eval_valid("cmd") FileToUpload.data.RESIZE(FileToUpload.data.SIZE()-1) 'del last byte, always added in upload -- this is the added line of code. file.from_blob(ServerSetting.Document_Root + "\\" + FileToUpload.filename, FileToUpload.data) msg = "<a href=\"/" + FileToUpload.filename + "\" target=\"_blank\">" + FileToUpload.filename + "</a> was uploaded<br /><br />" end if %> <head> <title>File Upload example</title> </head> <body bgcolor="#ffffff"> <%a5 ? msg %> <form action=" <%a5 ? request.script_name %> " method="POST" enctype="multipart/form-data"> <input type="file" name="FileToUpload" value=""><br /> <input type="submit" name="cmd" value="Upload File"> </form> </body> </html>
The one additional line of code is: FileToUpload.data.RESIZE(FileToUpload.data.SIZE()-1) 'del last byte, always added in upload
I have not seen this effect on file validity mentioned before and it may affect other file types also.
Thanks for reading and for all the helpful information I have found on this board.
Irwin
Comment