gpt4 book ai didi

javascript - jQuery 将变量发布到 php 并下载文件

转载 作者:行者123 更新时间:2023-11-27 23:42:15 25 4
gpt4 key购买 nike

我不确定我的代码是否正确,但我不断收到错误消息,指出调试器中不允许 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com