显示一些文本后在php中下载文件
嗨,我需要创建文件下载。下载填写表单、表单验证和数据库插入都在同一页面中。如果表单已提交,则需要使用“另存为”窗口自动触发文件下载。我将代码编写为:显示一些文本后在php中下载文件,php,header,download,Php,Header,Download,嗨,我需要创建文件下载。下载填写表单、表单验证和数据库插入都在同一页面中。如果表单已提交,则需要使用“另存为”窗口自动触发文件下载。我将代码编写为: if(isset($_POST['submit'])){ $u=$_POST['uname']; /*similarly getting all posted data*/ echo '<br><b>'.JText::_( 'Thank you for submitting your details...' ).'</
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}
if(isset($\u POST['submit'])){
$u=$_POST['uname'];
/*类似地,获取所有发布的数据*/
echo“
”.JText::(“感谢您提交详细信息…”);
$db=&JFactory::getDBO();
$query=“/*db插入查询*/”;
$db->setQuery($query);
$db->query();
$filee=basename($path);/*$path包含值形式$\u POST*/
$full=http://localhost/joomla/images/uploads/“.$filee;
?>
如果几秒钟后下载没有自动启动,
您可以在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}
if(isset($\u POST['submit'])){
$u=$_POST['uname'];
echo“
”.JText::(“感谢您提交详细信息…”);
$db=&JFactory::getDBO();
$query=“/*db插入查询*/”;
$db->setQuery($query);
$db->query();
$filee=basename($path);/*$path包含值形式$\u POST*/
$full=http://localhost/joomla/images/uploads/“.$filee;
?>
如果几秒钟后下载没有自动启动,
使用sleep();
等待一段时间我尝试了。但是在打印文本“谢谢提交…”之前,我会先睡觉,然后开始下载。我需要在页面中显示这些消息后开始下载。