我已经创建了一个YouTube搜索引擎下载MP3转换脚本.我用Jeckman’s YouTube Downloader来创建这个脚本.一切都很好,除了,我想将视频下载到服务器而不是将其下载到我的电脑.我想这样做,因为在下载之后,我将使用FFmpeg将视频转换为MP3.
有没有办法让视频下载到我的服务器而不是我的电脑?
<?PHP
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
header('Content-Type: "' . $mime . '"');
header('Content-disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-transfer-encoding: binary");
header('Pragma: public');
}
else
{
header('Content-Type: "' . $mime . '"');
header('Content-disposition: attachment; filename="' . $name . '"');
header("Content-transfer-encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
}
readfile($url);
exit;
}
// Not found
exit('File not found 8{');
?>
解决方法:
我找到了将YouTube文件存储到服务器的解决方案.我删除了标题内容并放入$download_video_file = file_put_contents($file_path,fopen($url,’r’));代替readfile($url);它像魔术一样工作! ^ _ ^
这是完整的代码:
<?PHP
// Check download token
if (empty($_GET['mime']) OR empty($_GET['token']))
{
exit('Invalid download token 8{');
}
// Set operation params
$mime = filter_var($_GET['mime']);
$ext = str_replace(array('/', 'x-'), '', strstr($mime, '/'));
$url = base64_decode(filter_var($_GET['token']));
$name = urldecode($_GET['title']). '.' .$ext;
// Fetch and serve
if ($url)
{
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{/*
header('Content-Type: "' . $mime . '"');
header('Content-disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-transfer-encoding: binary");
header('Pragma: public');
*/}
else
{/*
header('Content-Type: "' . $mime . '"');
header('Content-disposition: attachment; filename="' . $name . '"');
header("Content-transfer-encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
*/}
$download_video_file = file_put_contents($file_path, fopen($url, 'r'));
exit;
}
// Not found
exit('File not found 8{');
?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。