Beh per dirla tutta la procedura di upload e di progress bar FUNZIONA.
Ho preso uno script già pronto.
Io lo sto solo modificando per le mie esigenze e ora dà degli strani inspiegabili problemi.
Ad ogni modo facendo altre prove sono arrivato a scartare il JavaScript come responsabile del problema....
.... il responsabile sembra essere il codice ASP, anche se non so ancora come e perchè.....
Quindi se mi volete aiutare su quello anche se OT bene.... altrimenti mi potreste spostare lì.... oppure creo io un altro post là.
Comunque se volete un pò di codice ve lo posto.
La pagina della form ha semplicemente una form con un input file e che mi apre un popup con la pagina "Progress.asp?formName=NOMEFORM"
Dopodichè parte il codice per la progress bar... che è quello riportato sotto.
La prima parte (quella in JS) svolge egregiamente il suo dovere.
Il problema è nella seconda (ASP), dopo il primo End If (dalla definizione della classe in poi).
codice:
<%
If Request.Querystring("formName") <> "" Then %>
<script>
<!--
function ShowProgressBar(uploadForm) {
// recupero la form
var Form = uploadForm;
// Genera un intero unico come ID dell'upload
var ID = (new Date()).getTime() % 1000000000;
// Controllo come impostare la querystring in base ad eventuali parametri già passati
if(Right(Form.action,1) == "?")
{ Form.action = Form.action + "ID=" + ID; }
else if(InStr(Form.action,"?") == -1)
{ Form.action = Form.action + "?ID=" + ID; }
else if(InStr(Form.action,"?") != -1)
{ Form.action = Form.action + "&ID=" + ID; }
else if(Form.action == "")
{ alert("L\'action della form e\' vuoto!"); return false }
// Adesso che ho impostato l'ID nell'action della form effettuo la sua submit()
Form.submit();
// Imposto la pagina di destinazione (con l'aggiunta dell'ID)
var URL = window.location.pathname + "?ID=" + ID;
window.setTimeout(location.href = URL, 1000);
}
//============================================================================//
if (window.opener && !window.opener.closed)
ShowProgressBar(window.opener.document.<%= Request.Querystring("formName")%>);
else
alert("Nessuna finestra padre disponibile!");
//-->
</script>
<%
End If
class ProgressRecord
public CurrentFile
public CurrentFileBytes
public UploadedBytes
public TotalBytes
public ElapsedTime
public sub ReadRec(ID)
const UploadProgressTable = "ASPUploaderProgressTable"
dim ProgressTable
CurrentFile = ""
CurrentFileBytes = 0
UploadedBytes = 0
TotalBytes = 0
ElapsedTime = 0
Application.Lock
if not IsEmpty(Application(UploadProgressTable)) then
set ProgressTable = Application(UploadProgressTable)
ProgressTable.MoveFirst
ProgressTable.Find "ID = " & ID
if not ProgressTable.EOF then
CurrentFile = ProgressTable("CurrentFile").Value
CurrentFileBytes = ProgressTable("CurrentFileBytes").Value
UploadedBytes = ProgressTable("UploadedBytes").Value
TotalBytes = ProgressTable("TotalBytes").Value
ElapsedTime = DateDiff("s", ProgressTable("FirstUpdate").Value, ProgressTable("LastUpdate").Value) + 1
end if
end if
Application.UnLock
end sub
end class
function GetProgressRecord(ID)
set GetProgressRecord = new ProgressRecord
GetProgressRecord.ReadRec ID
end function
'###################################################################################
' INIZIO DELLA PARTE ESEGUITA SOLAMENTE SE C'E' LA DIRETTIVA
' DI AVVIARE LA PROGRESSBAR (tramite QueryString)
'###################################################################################
If Trim(Request.QueryString("ID")) <> "" And IsNumeric(Request.QueryString("ID")) Then
const RefreshInterval = 1 'Determines how often to refresh progress bar window (in seconds)
const TimesToWait = 7 'Determines how many refreshes without data are ok before progress bar window closes
const stProgress = 0, stWait = 1, stClose = 2 'Labels state of progress bar window
dim UploadID, RefreshCount, Rec, State
dim Percentage, SizeCompleted, TransferRate, SecondsLeft, TimeLeft, Title
Response.CacheControl = "no-cache" 'Prevents proxy caching
Response.Expires = -1 'Prevents browser caching
UploadID = Request.QueryString("ID")
RefreshCount = clng(Request.QueryString("Count"))
if IsEmpty(RefreshCount) then RefreshCount = 0
set Rec = GetProgressRecord(UploadID)
if Rec.UploadedBytes > 0 then 'Upload started.
State = stProgress
SizeCompleted = FormatNumber(Rec.CurrentFileBytes / 1024, 0, 0, 0, -1) & " KB"
TransferRate = FormatNumber(Rec.UploadedBytes / 1024 / Rec.ElapsedTime, 2, 0, 0, -1) & " KB/sec"
if Rec.TotalBytes > 0 then 'Browser sent content-length, and we can use it.
Percentage = fix(Rec.UploadedBytes / Rec.TotalBytes * 100) & "%"
SecondsLeft = fix(Rec.ElapsedTime * (Rec.TotalBytes / Rec.UploadedBytes - 1))
TimeLeft = SecondsLeft mod 60 & " sec"
if SecondsLeft > 60 then TimeLeft = (SecondsLeft mod 3600) \ 60 & " min " & TimeLeft
if SecondsLeft > 3600 then TimeLeft = SecondsLeft \ 3600 & "hour(s) " & TimeLeft
Title = Percentage & " completed"
else 'Very old or bad browser didn't send content-length.
Percentage = "50%"
TimeLeft = "<Unknown>"
Title = "File upload"
end if
elseif RefreshCount < TimesToWait then 'We are waiting for upload to begin.
State = stWait
Title = "File upload"
else 'Upload completed.
State = stClose
Title = "Closing upload"
end if
Response.Write "<?xml version=""1.0"" encoding=""iso-8859-1""?><!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Strict//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd""><html xmlns=""http://www.w3.org/1999/xhtml"" xml:lang=""en"" lang=""en""><head><title>"
Response.Write Title
Response.Write "</title>"
if State = stClose then
Response.Write "<script language=""javascript"">window.close();</script>"
else
Response.Write "<meta http-equiv=""refresh"" content="""
Response.Write RefreshInterval
Response.Write ";url=Progress.asp?ID="
Response.Write UploadID
Response.Write "&refreshing=1"
Response.Write "&Count="
Response.Write RefreshCount + 1
Response.Write """ />"
end if
Response.Write "</head><body tabindex=""1"" style=""margin: 8px; background-color: #E0E0E0"">"
if State = stProgress then
Response.Write "<table style=""font-family: Tahoma,Arial; font-size: 12px""><tr><td style=""padding: 2px; white-space: nowrap; font-weight: bold"">Uploading file:</td><td style=""padding: 2px; white-space: nowrap"">"
Response.Write Rec.CurrentFile
Response.Write "</td></tr><tr><td style=""padding: 2px; white-space: nowrap; font-weight: bold"">Size completed:</td><td style=""padding: 2px; white-space: nowrap"">"
Response.Write SizeCompleted
Response.Write "</td></tr><tr><td style=""padding: 2px; white-space: nowrap; font-weight: bold"">Transfer rate:</td><td style=""padding: 2px; white-space: nowrap"">"
Response.Write TransferRate
Response.Write "</td></tr><tr><td style=""padding: 2px; white-space: nowrap; font-weight: bold"">Time left:</td><td style=""padding: 2px; white-space: nowrap"">"
Response.Write TimeLeft
Response.Write "</td></tr></table><table style=""width: 100%; font-size: 8px; margin-top: 8px; border: 2px solid; border-top-color: #A0A0A0; border-right-color: #FFFFFF; border-bottom-color: #FFFFFF; border-left-color: #A0A0A0""><tr><td style=""background-color: #000080; width: "
Response.Write Percentage
Response.Write """></td><td></td></tr></table><div style=""position: absolute; bottom: 8px; width: 100%; text-align: center"">ASPUploader</div>"
elseif State = stWait then
Response.Write "<div style=""text-align: center; font-size: 24px; margin-top: 48px"">Please wait "
'# "Please Wait" animato "
dim i
for i = 0 to RefreshCount
Response.Write ".."
next
'# " " " " " " " " "
Response.Write "</div>"
Response.Write "<div style=""text-align: center; font-size: 16px; margin-top: 48px"">In attesa dell'inizio dell'upload</div>"
end if
Response.Write "</body></html>"
' FINE DELLA PARTE ESEGUITA SOLAMENTE SE C'E' LA DIRETTIVA DI AVVIARE LA PROGRESSBAR (tramite QueryString)
End If
%>
Se sapeste darmi una mano (voi di JS, oppure quelli di ASP, se mi ci spostate) mi risolvereste un problema enorme..... ci sono dietro da giorni e non riesco a capire cosa può cambiare eseguendo la stessa identica pagina su un altro browser (e non è che funziona su uno e sull'altro no.... funziona semplicemente su "un'altro browser"
).
Grazie