doushoubu5360 2018-02-26 12:04
浏览 135

PHP Youtube下载器API下载文件名videoplayback

I am using Youtube download API when i click on download button video is downloading but filename showing "videoplayback.MP4" My code:

<?php
$url="http://hddir.com/ajax/api.php?type=downlink&v=Is3S-6hHQLk";
$c=curl_init();
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
curl_setopt($c,CURLOPT_URL,$url);
$contents=curl_exec($c);
curl_close($c);
$someObject = json_decode($contents);
foreach($someObject as $obj){
$url=$obj->url;
$format=$obj->format;
echo '<a href="'.$url.'" download>video '.$format.'</a></br>';
}
?>

Result result of above code

  • 写回答

1条回答 默认 最新

  • dongpao1918 2018-02-26 12:18
    关注

    As a quick fix, HTML5 provides a download attribute you may use in your anchor tag, this allows you to specify the desired file name of the download. This relies on the end user using a browser which supports this tag.

    echo '<a href="'.$url.'" download="desiredfilename">video '.$format.'</a></br>';
    

    At the time of writing browser support is:

    • Chome: 14.0
    • Edge: 13.0
    • Firefox: 20.0
    • Safari: 10.1
    • Opera: 15.0

    There is no requirement to specify a file extension.

    More information can be found online including browser support, for example this W3 Schools Article

    Update: This will not work cross-origin, the file must be hosted on the same domain, as such this is not a solution for this particular problem unfortunately.

    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法