简体   繁体   English

显示一些文本后在php中下载文件

[英]File downloading in php after displaying some text

Hi I need to create file downloading. 嗨,我需要创建文件下载。 the fill up form for download and form validation and dB inserting all are in the same page. 用于下载,表单验证以及dB插入的填写表都在同一页面上。 if the form is submitted then file downloading needs to be automatically triggered with save as window. 如果提交了表单,则需要使用“另存为”窗口自动触发文件下载。 I wrote the code as: 我写的代码为:

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}

I need to print the "thanks for submitting.."..etc message before downloading.but now when I submit the fill up form download starts with out displaying the above text. 在下载之前,我需要打印“感谢提交.... etc”消息。但是现在,当我提交填写表格时,下载开始时不显示上述文本。 what should I do for making download after waiting some time? 等待一段时间后我应该怎么做进行下载?

You can use sleep() in php to delay the execution.So try like this 您可以在php中使用sleep()来延迟执行。

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}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM