2013-07-23 2 views
4

Я создал поисковую систему YouTube + скачать + конвертер MP3. Я использовал Jeckman's YouTube Downloader для создания этого скрипта. Все в порядке, за исключением того, что я хочу загрузить видео на сервер, а не загружать его на свой компьютер. Я хочу сделать это, потому что после загрузки будет конвертировать видео в MP3 с помощью FFmpeg.Загрузить видео на YouTube

Есть ли способ получить видео, загруженное на моем сервере, вместо моего компьютера?

download.php содержит следующий код:

<?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{'); 
?> 
+0

полоса из всего материала заголовка и изменения 'ReadFile()' для [file_get_contents()] (http://php.net/file_get_contents) –

+0

@MarcB Ничего не случилось. Хотя файл загружен в течение нескольких секунд, но файл не был сохранен в моей папке public_html или в любой папке! Любые другие предложения? – user2606457

ответ

2

Я узнал решение для хранения файлов 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{'); 
?> 
+0

Используя приведенный выше код на локальном сервере (appserv), файл создается с 0 байтами. Любые советы, чтобы заставить его работать на местном уровне? – Guttemberg

Смежные вопросы