2017-03-23 96 views
1
<form method="post" action="download.php?id=<?php echo uniqid(); ?>"> 
<input type="url" name="vidurl"> 
<button type="submit" name="submit">Submit</button> 
</form> 

在其他网页我下载使用文件夹下的验证码“下载”文件更新数据库[PHP]

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

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

回答

0

希望这会对你有用。

<?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', 
)