← Desenvolvimento

Contagem decrescente - Download

Lida 4132 vezes

Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Tambem é possivel, deixa-me fazer um rascunho que já 'posto' aqui.
Offline

=IceBurn= 
Membro
Mensagens 897 Gostos 3
Feedback +3

Troféus totais: 32
Trófeus: (Ver todos)
Windows User Level 6 Linux User Mobile User Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5

Ok, isto é um exemplo básico e funcional para o que tu pretendes:

Código: [Seleccione]
<?php
if&#40;isset&#40;$_COOKIE['download'&#93;&#41;&#41; &#123;
    
setcookie&#40;'download', '', time&#40;&#41; - 3600, '/'&#41;;
    
header&#40;'location&#58; http&#58;//dominio.com/arquivo.rar'&#41;;
    //exit;
&#125;
?>

<!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="pt" lang="pt">
  <head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>Download</title>
    <script type="text/javascript">
     function Set_Cookie( name, value, expires, path, domain, secure ) {

      var today = new Date();
      today.setTime( today.getTime() );

      if ( expires ) {
       expires = expires * 1000 * 60;
      }

      var expires_date = new Date( today.getTime() + (expires) );

      document.cookie = name + "=" +escape( value ) +
      ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
      ( ( path ) ? ";path=" + path : "" ) +
      ( ( domain ) ? ";domain=" + domain : "" ) +
      ( ( secure ) ? ";secure" : "" );
   }

   function fnHide(secs){
 
   secs--;
       
    if(secs>0) {
       
document.getElementById("waiting").innerHTML = 'Please wait while we transfer your file. Estimated wait time: <b>'+secs+'</b> seconds.';
    window.setTimeout("fnHide("+secs+")",1000);
       
    } else {
 
    Set_Cookie('download', '1', 1, '/', '', ''); // -> 1 minuto
document.getElementById("waiting").innerHTML = '<a href="#" onclick="javascript: window.location.reload();">Carregue aqui para fazer download automaticamente</a>';        
 
   }
       
  }
  </script>
  </head>
<body>

<div id="waiting"></div>

 <p>
  <a href="#" onclick="javascript: fnHide(25); return false;">Download</a>
 </p>
 


 </body>
</html>


PS: Mantive a função JavaScript (fnHide) já postada anteriormente.

EDIT: Havia um pequeno erro,  já foi corrigido.