我正在尝试下载.MP4 Extension
文件,PHP Code In Specific Folder
我的代码仅适用于.MP4扩展程序,但我无法使用此代码下载此URL MP4视频
我正在尝试此代码
function download ($url, $location){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec ($ch);
$error = curl_error($ch);
curl_close ($ch);
$file = fopen($location, "wb");
fwrite($file, $data);
fclose($file);
return 'done';
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Video URL (Only With .MP4 Extension):
<input type="text" name="url" placeholder="Video URL Here" required/><br>
Video ID Number:
<input type="text" name="id" placeholder="Video ID Nmber eg:1,2,3" required/><br>
<input type="submit"/>
</form>
</body>
</html>
<?php
@$url = $_POST['url'];
@$ID = $_POST['id'];
$SCRIPT_DIR = dirname(__FILE__);
$TEMP_DIR = $SCRIPT_DIR . '/videos/';
$location = $TEMP_DIR . $ID . '.mp4';
if(isset($_POST['url'])){
echo download($url, $location);
}
答案 0 :(得分:1)
之前我使用过此代码从同一来源下载视频:
function download ($url, $location){
$fp = fopen($location, "w+");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
return 'done';
}