0

嗨,我需要创建文件下载。用于下载和表单验证的填写表格以及插入 dB 都在同一页面中。如果表单已提交,则需要使用另存为窗口自动触发文件下载。我将代码编写为:

if(isset($_POST['submit'])){
$u=$_POST['uname'];
/*similarly getting all posted data*/
echo '<br><b>'.JText::_( 'Thank you for submitting your details...' ).'</b>';
 $db =& JFactory::getDBO();
  $query = "/*db inserting query*/";
  $db->setQuery( $query );
  $db->query();

  $filee=  basename($path); /*$path contains value form $_POST*/
   $full='http://localhost/joomla/images/uploads/'.$filee;

  ?>
 <br><b>
  <span>If the download  does not start automatically in a few seconds, <a href="<?php     echo JURI::base(); ?>/images/myfile/<?php echo $filee;?>" target="_blank"><b> Click this link</b></a></span></b>


 <?php


   header('Content-Description:File Transfer');
   header("Content-type:application/pdf");
   header("Content-type:application/zip");
   header("Content-type:image/jpeg");
   header("Content-type:image/png");
   header("Content-type:application/msword");
   header("Content-Disposition: attachment; filename=".$filee."");
   header("Cache-control: private");
   readfile($full);


   }
 else{ code for printing fill up form}

我需要在下载之前打印“感谢提交..”..etc 消息。但是现在当我提交填写表格时,下载开始时不显示上述文本。等待一段时间后我应该怎么做才能下载?

4

1 回答 1

0

你可以sleep()在php中使用来延迟执行。所以试试这样

if(isset($_POST['submit'])){
$u=$_POST['uname'];
echo '<br><b>'.JText::_( 'Thank you for submitting your details...' ).'</b>';
 $db =& JFactory::getDBO();
  $query = "/*db inserting query*/";
  $db->setQuery( $query );
  $db->query();
  $filee=  basename($path); /*$path contains value form $_POST*/
  $full='http://localhost/joomla/images/uploads/'.$filee;

  ?>
 <br><b>
  <span>If the download  does not start automatically in a few seconds, <a href="<?php     echo JURI::base(); ?>/images/myfile/<?php echo $filee;?>" target="_blank"><b> Click this link</b></a></span></b>


 <?php

   sleep(10);//Will delay for 10 seconds

   header('Content-Description:File Transfer');
   header("Content-type:application/pdf");
   header("Content-type:application/zip");
   header("Content-type:image/jpeg");
   header("Content-type:image/png");
   header("Content-type:application/msword");
   header("Content-Disposition: attachment; filename=".$filee."");
   header("Cache-control: private");
   readfile($full);


   }
 else{ code for printing fill up form}
于 2013-10-23T09:25:00.743 回答