%@ Language=JavaScript %>
<%
/***************************************************************************************************
* uploadFile.hh.asp: Uploads a file and stores it in the file system and the database
***************************************************************************************************
* PARAMETERS:
* - FILE (in): The source file path
*
* RETURN VALUE:
* Creates an HTML file that calls back the hosting document with the resulting file handle
*
* NOTES:
* We use here the SAFileUp component.
***************************************************************************************************/
Response.Expires = -1
Response.Buffer = true
Server.ScriptTimeout = 600000;
%>
<%
try { VERIFY();}catch (e){SIPError(e);};
%>
images/upload-anim.gif" hspace="7" vspace="7">
00
00
<%
if(Request.ServerVariables("HTTP_METHOD") == "POST")
{
try{
var oUploader = Server.CreateObject("SoftArtisans.FileUp");
oUploader.codepage = Session("ENCODING").toLowerCase()=='utf-8'?65001:Session("ENCODING").toLowerCase().replace('windows-','');
oUploader.Path = Application("APP_TEMP_PATH");
}catch(e){
dbg("Error SoftArtisans.FileUp : "+e.description)
Response.End
}
try{
var oDosInfo = Server.CreateObject("DSOleFile.PropertyReader");
}catch(e){
dbg("Error DSOleFile.PropertyReader : "+e.description)
Response.End
}
var ID=0, EXT='', DIR='', FOLDER=0, STORAGE='';
try{
if (!oUploader.IsEmpty) {
ID = oUploader.Form.Item("ID");
EXT = oUploader.Form.Item("EXT");
DIR = oUploader.Form.Item("DIR");
STORAGE = oUploader.Form.Item("STORAGE");
if (!isnull(ID) && !isnull(DIR)){
try{
var sFileName = Application("APP_"+STORAGE+"_PATH") + DIR + "\\" +ID + "." + EXT;
dbg("sFileName="+sFileName)
// save file
oUploader.SaveAs(sFileName);
dbg("File has been saved");
try
{
/* if(Application("APP_STORAGE_PATH_IMPORT"))
{
var sPth4Import = String(Application("APP_STORAGE_PATH_IMPORT"));
with(fso = new ActiveXObject("Scripting.FileSystemObject"))
{
dbg("copy to:" + sPth4Import);
CopyFile(sFileName, sPth4Import);
}
}
*/
if(Application("ADM_UPLOADFILES_2DB") && Application("ADM_UPLOADFILES_2DB")=='ON')
{
var stream = Server.CreateObject("adodb.stream");
stream.Open();
stream.Type = adTypeBinary;
stream.LoadFromFile(sFileName);
var rs = tableInsert("TBL_FILES_TO_EXPORT");
var d = new Date();
var date = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+d.getDate()+' '+d.getHours()+':'+d.getMinutes()+':'+d.getSeconds();
try
{
rs.Fields("FBLOB").AppendChunk(stream.read());
rs("ID") = getSeq('TBL_FILES_TO_EXPORT_SEQ');
rs("FILE_ID") = ID;
rs("TABLE_NAME") = "CNT_FILES";
rs("ACTION_TYPE") = "INSERT";
rs("STATUS_NET") = "";
rs("CREATED_DATE") = date;
rs("URL") = DIR + "\\" +ID + "." + EXT;
if (PLSQL) rs.UpdateBatch();
else rs.Update();
}
catch(e)
{
dbg("Failed to update : " + e.description);
SIPError(e);
}
}
}
catch(e)
{
// dbg(sPth4Import+"->"+e.description);
dbg(e.description);
SIPError(e);
}
var oDocProp = oDosInfo.GetDocumentProperties(sFileName);
// get document properties
var sCategory = trim(oDocProp.Category);
var sComments = trim(oDocProp.Comments);
var sTitle = trim(oDocProp.Title);
var sSubject = trim(oDocProp.Subject);
var sAuthor = trim(oDocProp.Author);
var sKeywords = trim(oDocProp.Keywords);
// property missing flag
var E_PROPERTY_MISSING = false;
// extenssions to chech properties
var PROP_CHECK = {
doc:true,
ppt:true,
xls:true
}
// check properties
if(PROP_CHECK[EXT]) {
//E_PROPERTY_MISSING = E_PROPERTY_MISSING || (isnull(sCategory)||sCategory=='');
//E_PROPERTY_MISSING = E_PROPERTY_MISSING || (isnull(sComments)||sComments=='');
//E_PROPERTY_MISSING = E_PROPERTY_MISSING || (isnull(sTitle)||sTitle=='');
//E_PROPERTY_MISSING = E_PROPERTY_MISSING || (isnull(sSubject)||sSubject=='');
//E_PROPERTY_MISSING = E_PROPERTY_MISSING || (isnull(sAuthor)||sAuthor=='');
}
// if property error do not update file
if(!E_PROPERTY_MISSING) {
// update file's data
updateFile(
ID,
oUploader.UserFilename,
oUploader.TotalBytes,
EXT,
DIR,
oUploader.ContentType,
sTitle,
sSubject,
sCategory,
sComments,
sAuthor,
sKeywords,
STORAGE
);
//
// if(FOLDER) {
// linkFileToFolder(ID, FOLDER);
// }
Response.Write("");
} else {
Response.Write("");
}
}
catch (e) {
dbg("Upload File ERROR: "+e.description)
Response.Write("");
ID = 0;
}
}
} else {
Response.Write("");
}
}catch(e)
{
dbg('General Upload File Error: '+e.description);
}
}
else
{
//this is an empty GET request, do noting yet...
}
%>