مشکل در نوشت هدر برای دانلود

bahy_my

Active Member
سلام. من یه تیکه کد دارم که می خوام ویدیو رو به صورت attachment برای کاربر در بیاره.
آدرس فایل مورد نظر رو می ذارم اما موقع اجرا فایل خالی رو برام میاره. نا گفته نمونه که کدهای زیادی توی صفحه هست.
و دیگه فایلی که این عملیات رو انجام میده به صورت جی کوئری لود میشه.
نمی دونم این دو مورد تأثیر دارن یا نه ولی براتون کد رو می ذارم.
PHP:
$db->check_array_attack($_GET);
$db->check_array_attack($_POST);

$st = $db->select_db("setting", "*", 1);
$site_url = $st[0]['siteurl'];
$name = $_POST['name'];
        $age = $_POST['age'];
        $city = $_POST['city'];
        $job = $_POST['job'];
        $email = $_POST['email'];
        $filename = $_POST['file'];
        $phone = $_POST['phone'];
        $field = $_POST['field'];




if (isset($_POST['download'])) {

    if (isset($_POST['free'])) {
       
$st = $db->select_db("downloads", "*", 2, "phone='" . $phone . "'");
$duration=0;
        if ($db->rec_num[2] > 0){
            $last_download = $st[0]['date'];
        $now = time();


        $duration = $now - $last_download;


    }
   
       
        if (($db->rec_num[2]==0) or($duration > 2592000)
    ) {


        setcookie('name', $name, time() + (86400 * 30), "/"); // 86400 = 1 day
        setcookie('age', $age, time() + (86400 * 30), "/"); // 86400 = 1 day
        setcookie('city', $city, time() + (86400 * 30), "/"); // 86400 = 1 day
        setcookie('job', $job, time() + (86400 * 30), "/"); // 86400 = 1 day
        setcookie('email', $email, time() + (86400 * 30), "/"); // 86400 = 1 day
        //setcookie('member', $phone, time() + (86400 * 30), "/"); // 86400 = 1 day
        setcookie('phone', $phone, time() + (86400 * 30), "/"); // 86400 = 1 day


        $db->insert_db('downloads',
            '`id`, `name`, `age`, `city`, `job`, `email`, `file`, `date`, `field`, `phone`',
            "NULL,
                                     '" . $name . "',
                                     '" . $age . "',
                                     '" . $city . "',
                                     '" . $job . "',
                                     '" . $email . "',
                                     '" . $filename . "',
                                     '" . time() . "',
                                     '" . $field . "',
                                     '" . $phone . "'");


$fileName = basename($filename);
$filePath = 'uploads/upload_article_video/'.$fileName;
if(!empty($fileName) && file_exists($filePath)){
    // Define headers
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$fileName);
    header("Content-Type: video/mp4");
    header("Content-Transfer-Encoding: binary");
   
    // Read the file
    readfile($filePath);
    exit;
}else{
    echo 'The file does not exist.';
}               
           
        } else {
        print $msg = 'شما تنها می توانید یک بار در ماه رایگان فایل دانلود کنید.';
    }
    }
}


همونطور که می بینید کد اصلی اینه:
PHP:
$fileName = basename($filename);
$filePath = 'uploads/upload_article_video/'.$fileName;
if(!empty($fileName) && file_exists($filePath)){
    // Define headers
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=".$fileName);
    header("Content-Type: video/mp4");
    header("Content-Transfer-Encoding: binary");
   
    // Read the file
    readfile($filePath);
    exit;
}else{
    echo 'The file does not exist.';
}
 

bahy_my

Active Member
و البته اینم بگم که صفحه ای که کاربر در حال اجرای اونه با کد htaccess آدرسش بازنویسی شده. گفتم اینم بگم
 

جدیدترین ارسال ها

بالا