Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Fernando_DMK

Upload com barra de progresso

Recommended Posts

O código irá exibir parte na barra de progresso ao carregar qualquer arquivo utilizando ASP. você pode integrá-lo com upload.

 

<%@ Language=VBScript %>
<%Option explicit
' prgress bar
'-----------------------------------------
sub main()
	
	Dim countinner, countouter, count1, count2, j,k
	
	'if Request.Form ("Submit") = "Submit" then
	'else
		call display	
	'end if
	
end sub

'-----------------------------------------
sub display()
%>
		<html>
		<head>
		<title>Progress Bar</title>
		<script language="javascript">
		<!--

		var timerID = null;
		var timerRunning = false;
		var timeValue = 1000;  //o incremento de tempo em mS
		var count = 0;
		var finish = false;
		/ / carregar as imagens para a barra de progresso
		image00 = new Image(); image00.src='image-00.gif';
		image01 = new Image(); image01.src='image-01.gif';
		image02 = new Image(); image02.src='image-02.gif';
		image03 = new Image(); image03.src='image-03.gif';
		image04 = new Image(); image04.src='image-04.gif';
		image05 = new Image(); image05.src='image-05.gif';
		image06 = new Image(); image06.src='image-06.gif';
		image07 = new Image(); image07.src='image-07.gif';
		image08 = new Image(); image08.src='image-08.gif';
		image09 = new Image(); image09.src='image-09.gif';
		image10 = new Image(); image10.src='image-10.gif';


		function increment() {
			count += 1;
			if (count == 0) {document.images.bar.src=image00.src;}
			if (count == 1) {document.images.bar.src=image01.src;}
			if (count == 2) {document.images.bar.src=image02.src;}
			if (count == 3) {document.images.bar.src=image03.src;}
			if (count == 4) {document.images.bar.src=image04.src;}
			if (count == 5) {document.images.bar.src=image05.src;}
			if (count == 6) {document.images.bar.src=image06.src;}
			if (count == 7) {document.images.bar.src=image07.src;}
			if (count == 8) {document.images.bar.src=image08.src;}
			if (count == 9) {document.images.bar.src=image09.src;}
			/ / Se você quer que ele repita o bar continuamente em seguida, use esta linha
			if (count == 10) {document.images.bar.src=image10.src; count=-1;}
						/ / Se você quer parar de repetir o bar então, usar essa linha
			//if (count == 10) {document.images.bar.src=image10.src; end();}
		}

		function stopclock() {
			if (timerRunning)
				clearInterval(timerID);
			timerRunning = false;	
		}

		function end() {
			if (finish == true) {
				stopclock();
				window.close();
			}
			else {
				finish = true; 
			}
		}

		function startclock() {		
			stopclock();
			timerID = setInterval("increment()", timeValue);
			timerRunning = true;
			document.images.bar.src=image00.src;
		}

		function Send_onclick(frmSubmit) {
			startclock();
			frmSubmit.submit();			
		}

		//-->
		</script>		
		
		<head>
		<body>
		
		Agurade porfavor.<br><br>
		<img src="image-00.gif" name="bar" align="middle">

		<form name="frmProgressBar" action="finish.asp" method="post">
		<INPUT type="submit" value="Submit" name="Submit" LANGUAGE=javascript onclick="return Send_onclick(frmProgressBar)">
		</form>		

		</body>
		</html>
<%
end sub

'-----------------------------------------
call main
%>

abaixo um code completo

 

Upload.asp

<HTML>
<head>
<%
Set UploadProgress = Server.CreateObject("Persits.UploadProgress")
PID = "PID=" & UploadProgress.CreateProgressID()
barref = "framebar.asp?to=10&" & PID
%>

<script LANGUAGE="JavaScript">
function ShowProgress()
{
  strAppVersion = navigator.appVersion;
  if (document.MyForm.FILE1.value != "" || document.MyForm.FILE2.value != "" || document.MyForm.FILE3.value != "")
  {
    if (strAppVersion.indexOf('MSIE') != -1 && strAppVersion.substr(strAppVersion.indexOf('MSIE')+5,1) > 4)
    {
		if( strAppVersion.indexOf("Macintosh") != -1 && strAppVersion.charAt(0) >= 3 )
		{
			window.open('<% = barref %>&b=NN','','width=370,height=115', true);
		}
		else
		{
			winstyle = "dialogWidth=385px; dialogHeight:140px; center:yes";
			window.showModelessDialog('<% = barref %>&b=IE',null,winstyle);
		}
    }
    else
    {
      window.open('<% = barref %>&b=NN','','width=370,height=115', true);
    }
  }
  return true;
}
</SCRIPT> 
</head>
<BODY BGCOLOR="#FFFFFF">
<FORM NAME="MyForm" method="POST" enctype="multipart/form-data" ACTION="aspUpload.asp?<%=PID%>" OnSubmit="return ShowProgress();">
<!--<FORM NAME="MyForm" method="POST" enctype="multipart/form-data" ACTION="progress_upload.asp?<%=PID%>" OnSubmit="return ShowProgress();">
   <FORM METHOD="POST" ENCTYPE="multipart/form-data" ACTION="aspUpload.asp">-->
      <INPUT TYPE="FILE" SIZE="40" NAME="FILE1"><BR>
      <INPUT TYPE="FILE" SIZE="40" NAME="FILE2"><BR>
      <INPUT TYPE="FILE" SIZE="40" NAME="FILE3"><BR>
   <INPUT TYPE=SUBMIT VALUE="Upload!">
   </FORM>
</BODY>
</HTML>
AspUpload.asp

<HTML>
<body>
<%response.buffer=true
Server.ScriptTimeout = 99999999%>
<%
'AspUpload
Set Upload = Server.CreateObject("Persits.Upload")

    Upload.ProgressID = Request.QueryString("PID") 'faz parte do carregando

Upload.OverwriteFiles = False
pasta = Server.MapPath("fotos/")
Upload.Save pasta
	Set Foto1 = Upload.Files("FILE1")
    Set Foto2 = Upload.Files("FILE2")
    Set Foto3 = Upload.Files("FILE3")

nome_arquivo = Foto1.FileName
nome_arquivo2 = Foto2.FileName
nome_arquivo3 = Foto3.FileName

response.Write nome_arquivo &"<br>"
response.Write nome_arquivo2 &"<br>"
response.Write nome_arquivo3 &"<br>"
response.End()

%>
</BODY>
</HTML>
bar.asp

<%@EnableSessionState=False%>

<%
  Response.Expires = -1
  PID = Request("PID")
  TimeO = Request("to")


  Set UploadProgress = Server.CreateObject("Persits.UploadProgress")

  format = "%TUploading files...%t%B3%T%R left (at %S/sec) %r%U/%V(%P)%l%t"

  bar_content = UploadProgress.FormatProgress(PID, TimeO, "#00007F", format)

  If "" = bar_content Then
%>
<HTML>
<HEAD>
<TITLE>Upload Finished</TITLE>
<script LANGUAGE="JavaScript">
function CloseMe()
{
	window.parent.close();
	return true;
}
</SCRIPT>
</HEAD>
<BODY OnLoad="CloseMe()">
</BODY>
</HTML>
<%
  Else    ' Not finished yet
%>
<HTML>
<HEAD>

<!--%  If left(bar_content, 1) <> "." Then %-->

<meta HTTP-EQUIV="Refresh" CONTENT="1;URL=<%
 Response.Write Request.ServerVariables("URL")
 Response.Write "?to=" & TimeO & "&PID=" & PID %>">

<!--% End If %-->

<TITLE>Uploading Files...</TITLE>

<style type='text/css'>td {font-family:arial; font-size: 9pt } td.spread {font-size: 6pt; line-height:6pt } td.brick {font-size:6pt; height:12px}</style>

</HEAD>
<BODY BGCOLOR="#C0C0B0" topmargin=0>
<% = bar_content %>
</BODY>
</HTML>

<% End If %>
framebar.asp

<%@EnableSessionState=False%>
<% Response.Expires = -1 %>

<HTML>
<HEAD>
<TITLE>Uploading files</TITLE>
<style type='text/css'>td {font-family:arial; font-size: 9pt }</style>
</HEAD>

<% If Request("b") = "IE" Then %> <!-- Internet Explorer -->
<BODY BGCOLOR="#C0C0B0">
<IFRAME src="bar.asp?PID=<%= Request("PID") & "&to=" & Request("to") %>" title="Upload Progress" noresize scrolling=no
frameborder=0 framespacing=10 width=369 height=65></IFRAME>
<TABLE BORDER="0" WIDTH="100%" cellpadding="2" cellspacing="0">
  <TR><TD ALIGN="center">
     To cancel uploading, press your browser's <B>STOP</B> button.
  </TD></TR>
</TABLE>
</BODY>

<%Else%> <!-- Netscape Navigator etc ... -->

<FRAMESET ROWS="65%, 35%" COLS="100%" border="0" framespacing="0" frameborder="NO">
<FRAME SRC="bar.asp?PID=<%= Request("PID") & "&to=" & Request("to") %>" noresize scrolling="NO" frameborder="NO" name="sp_body">
<FRAME SRC="note.htm" noresize scrolling="NO" frameborder="NO" name="sp_note">
</FRAMESET><noframes></noframes>

<%End If%>

</HTML>
note.asp

<HTML>
<HEAD>
<style type='text/css'>td {font-family:arial; font-size: 9pt } </style>
</HEAD>

<BODY BGCOLOR="#C0C0B0">

<TABLE WIDTH=100%>
  <TR><TD>
    To cancel uploading, press your browser's <B>STOP</B> button.
  </TD></TR>
</TABLE>

</BODY>
</HTML>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.