Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载文件时更新数据库[PHP]_Php_Mysql_Download_Youtube Dl - Fatal编程技术网

下载文件时更新数据库[PHP]

下载文件时更新数据库[PHP],php,mysql,download,youtube-dl,Php,Mysql,Download,Youtube Dl,现在的问题是如何为下载的文件分配一个id(从上一页获取)并更新数据库中的文件地址以将其提供给用户?希望这对您有用 <?php $id = $_GET['id']; $url = $_POST['vidurl']; $cmd = 'youtube-dl -o /downloads/%(title)s.%(ext)s '. escapeshellarg($url); $exec = shell_exec($cmd); ?> 希望这对你有用 <?php $id = $_

现在的问题是如何为下载的文件分配一个id(从上一页获取)并更新数据库中的文件地址以将其提供给用户?

希望这对您有用

<?php
$id = $_GET['id'];      
$url = $_POST['vidurl'];
$cmd = 'youtube-dl -o /downloads/%(title)s.%(ext)s '. escapeshellarg($url);
$exec = shell_exec($cmd);
?>

希望这对你有用

<?php
$id = $_GET['id'];      
$url = $_POST['vidurl'];
$cmd = 'youtube-dl -o /downloads/%(title)s.%(ext)s '. escapeshellarg($url);
$exec = shell_exec($cmd);
?>
<?php
//first solution

$id = $_GET['id'];      
$url = $_POST['vidurl'];
$cmd = 'youtube-dl -o /downloads/'.$id.'_%(id)s.%(ext)s '. escapeshellarg($url);
$output = shell_exec($cmd);

//second solution

//print_r($output); will give you the following output

foreach($output as $key => $value) {
    if(strpos($value, 'destination') === false) {
        // download failed or some error message
    } else {
        $destination = explode(':', $value)[1]; //full path with file id and extension
        //rename your file here here
        //$rename = rename($destination, $newdesitination);
        //insert in database
    }
}
?>
output: array (
  0 => '[youtube] Setting language',
  1 => '[youtube] XCj-wJB5j4c: Downloading video webpage',
  2 => '[youtube] XCj-wJB5j4c: Downloading video info webpage',
  3 => '[youtube] XCj-wJB5j4c: Extracting video information',
  4 => '[download] Destination: /downloads/YourID_XCj-wJB5j4c.flv',
[download] 100.0% of 10.48M at   185.11k/s ETA 12:00',
)