单击提交按钮时,我使用以下代码将数据存储在 wordpress 数据库中,现在代码通过将数据提交到 wordpress 数据库来工作。
if ($_POST['subscribe_btn'])
{
require("connect.php");
$user = $_POST['user'];
$email = $_POST['email'];
if($user)
{
if(preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email)){
$query=mysql_query("SELECT * FROM wp_newslettter WHERE email='$email'") or exit(mysql_error());
$numrows= mysql_num_rows($query);
if($numrows == 0 )
{
mysql_query("INSERT INTO wp_newslettter (`name`,`email`) VALUES ('$user','$email')")or exit(mysql_error());
}
else
$errmsg = "email address already exists";
}
else
$errmsg = "Please enter a valid email address";
}
else
$errmsg = "Please enter your username";
}
我现在要做的是,一旦将数据保存到数据库中,我想强制下载存储在我的主题中的 pdf,我对 wordpress 真的很陌生,无法访问文件路径,我有完成以下代码但没有文件下载,请对此提供任何帮助,我的表单操作如下action='$_SERVER[REQUEST_URI]'
/ **数据提交后下载pdf的代码* /
$a = bloginfo('template_url');
$file= $a . "/pdf/default.pdf";
$path_parts = pathinfo($file);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc":
case "docx": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header("Content-type: $ctype");
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate , post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
我无法通过执行以下代码来读取文件