2015-11-06 32 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