2015-11-06 29 views
1

我不确定我的代码是否正确,但我一直收到一个错误,说明调试器中不允许使用postjQuery发布变量到php并下载文件

我试图发送我的JavaScript变量 - 下载URL &新的文件名 - 到我的PHP文件和PHP然后下载.mp3。

的jQuery:

$.post('https://scriptkitti.github.io/Articles/Files/DownCloud.php', { 
    'filePath': url + '?client_id=' + client, 
    'fileTitle': title 
}); 

PHP:

<?php 
    if (isset($_POST['fileTitle'], $_POST['filePath'])) { 
     $fileTitle = $_POST['fileTitle']; 
     $filePath = $_POST['filePath']; 
     header('Content-Type: audio/mp3'); 
     header('Content-Disposition: attachment; filename="' . $fileTitle . '.mp3";'); 
     header('Pragma: public'); 
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
     header('Content-Length: ' . filesize($filePath)); 
     readfile($filePath); 
     exit; 
    } 
?> 

回答

1

链接要发布不执行。我去了它,它下载了PHP源代码。根据这个answer,github页面不执行服务器端代码(php),它只是用于静态内容(html,css,js等)。

+0

这将解释许多事情。谢谢! – HovyTech