php中的文件下载问题

时间:2014-01-18 11:34:44

标签: php

我已经编写了下载文件所需的全部代码,但不知道为什么它无法正常下载我的download.php文件。请建议解决方案

INDEX FILE

    <?php
    if(isset($_REQUEST['send'])){
        $name = $_REQUEST['name'];
        $email = $_REQUEST['email_id'];
        $contact = $_REQUEST['contact_no'];
        if(empty($name) || empty($contact) || empty($email)){
            $err= "Please Fill the Fields.";
        } else if(!preg_match("/^[(a-z)(A-Z) ]{2,50}$/", $name) || !preg_match("/^[(a-z)(0-9._-]+@[(a-z)(0-9)]+\.[(a-z).]{2,5}$/", $email) || !preg_match("/^[0-9]{10}$/", $contact)){
            $err= "Please Enter Valid Details";
        } else {
            mail($email, "The Free Template From xyz", "Here is the link for the free template. 
            http://www.xyz.com/download.php?download_file=blue.zip ", "From: sales@xyz.com");
            mail("sales@xyz.com", "Template Downloader Details", "Details:- \n Username: $name \n Email: $email \n Contact No: $contact" ,"From: $email");
            $err= "The Download link has been sent to your E-mail ID.";
        }
    }
 ?>

下载档案

<?php
    if(isset($_REQUEST['download_file'])){
        $path = $_SERVER['DOCUMENT_ROOT']."/templatefile/";
        $fullPath = $path.$_GET['download_file'];
        $path_parts = pathinfo($fullPath);

        header("Content-type: application/zip");
        header("Content-Dispostion: attachment; filename=\"".$path_parts['basename']."\"");
        readfile($fullPath);
    }
    header("Location: free-template.html");
?>

0 个答案:

没有答案