doutan5337 2014-06-11 08:54
浏览 28

我的download.php脚本发送了一个损坏的文件

I am having difficulty working out my download.php script. The customer gets a unique download link generated from my database and when they click it on it is meant to send them the file from my server. Only in my case the zip file is always corrupt and bigger then the original file. Original file is 68KB and the downloaded file ends up being 90KB.

Here is my code that sends the file to the browser:

<?php 
$actual_link = "http://$_SERVER[HTTP_HOST]";
$post_id = $wpdb->get_results("SELECT transaction_id FROM slx_jomsocial_plugin_orders WHERE (transaction_id ='". $tx ."' and unique_code='". $token ."')");
$rowCount = $wpdb->num_rows;
if($rowCount==1){
$name="Unzip_First_Video_Embedding.zip";
$file_url=$actual_link."/jomsplugins/".$name;   
header("Content-type: application/x-file-to-save"); 
header("Content-Disposition: attachment; filename=".$name); 
readfile($file_url);
       echo "<h1>Thank you ".$name=$_SESSION['s_name']." For downloading the plugins.</h1><br />";
}else{
       echo "<h1>You are not permitted to downlaod, Please purchase plugin first.</h1> <br /><div style=\"margin-left: 25%;margin-top: 1%;\"><a href=\"http://code-grab.com/\" title=\"Code-grab\">Click Here</a></div>";
}
?>

What am I doing wrong here?

UPDATE:

I have been experimenting with the script but still my files come out corrupted (Unzipping them gives a .cpgz file). Here is my current script now:

<?php 

$actual_link = "http://$_SERVER[HTTP_HOST]";
$post_id = $wpdb->get_results("SELECT transaction_id FROM slx_jomsocial_plugin_orders WHERE (transaction_id ='". $tx ."' and unique_code='". $token ."')");
$rowCount = $wpdb->num_rows;
if($rowCount==1){

// set example variables
$filename = "Unzip_First_Video_Embedding.zip";
$filepath = $actual_link."/jomsplugins/";

// http headers for zip downloads
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");
ob_end_flush();
ob_clean();
flush();
@readfile($filepath.$filename);
ob_clean();
flush();
exit;
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
    • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错