我不确定我的代码是否正确,但是我不断收到错误消息,指出调试器中不允许使用post
。
我正在尝试将我的JavaScript变量-下载网址和新文件名-发送到我的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;
}
?>
最佳答案
您发布到的链接未执行。我去了,它下载了PHP源代码。根据此answer,github页面不会执行服务器端代码(php),仅用于静态内容(html,css,js等)
关于javascript - jQuery将变量发布到php并下载文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33574487/