gpt4 book ai didi

php - 使用 file_get_contents 下载内容然后删除

转载 作者:可可西里 更新时间:2023-11-01 00:56:36 33 4
gpt4 key购买 nike

目前我发现这个网站的音乐相关工具非常方便,它为文件主机提供了一个镜像,我正在尝试使用 file_get_contents 下载一些 MP3 并在推送到这个文件主机镜像后将其删除。

当前代码是这样的..

$mp3 = 'http://www.example.com/song.mp3';
$name = 'song';
file_put_contents('tmp/'.$name.'.mp3',file_get_contents($mp3));

它将存储我们试图收集的 MP3,但在保存此信息后,我希望它通过我们找到的此文件镜像上的函数运行 API然后从我们的 tmp 目录中删除 MP3 文件。

网站是filemack

最佳答案

include('filemack.class.php');

// set path to temp directory
$temp_directory = dirname(__FILE__).'/tmp';

// set direct url to mp3
$mp3_url = 'https://www.filemack.com/embed/stream-demo.mp3';

// set name of mp3
$name = 'song';

// download file to temp directory
file_put_contents($temp_directory.'/'.$name.'.mp3',file_get_contents($mp3_url));

## start the filemack class
$filemack = new filemack;

## set your api key
$filemack->api_key = 'YOUR_API_KEY';

## set your api secret
$filemack->api_secret = 'YOUR_API_SECRET';

## enable individual hosts
$filemack->clicknupload = 1;
$filemack->dopefile = 1;

## or enable all of them
$filemack->all();

## change embed color 1
$filemack->embed_color_1 = '375a7f';

## change embed color 2
$filemack->embed_color_2 = 'ffffff';

## upload the file
#$links = $filemack->upload($temp_directory.'/'.$name.'.mp3');

## upload the file with new filename
$links = $filemack->upload($temp_directory.'/'.$name.'.mp3',$name.'.mp3');

// file has been pushed to filemack so delete now
unlink($temp_directory.'/'.$name.'.mp3');

## links variable will be an array
Array
(
[success] => 1
[embed] => <iframe src="https://www.filemack.com/embed/YdugtL8sSzV5?c1=375a7f&c2=ffffff" frameborder="0" scrolling="none" width="100%" height="64"></iframe>
[links] => Array
(
[filemack] => https://www.filemack.com/YdugtL8sSzV5
[clicknupload] => https://www.filemack.com/cu_tQwdzijxCJpmOIqd
[zippyshare] => https://www.filemack.com/zs_fL6CxCymd7EUe9Qh
[dopefile] => https://www.filemack.com/df_rPNgoMH7pznIK6rq
[affix] => https://www.filemack.com/af_c54jPe26dfcEc30a
[tusfiles] => https://www.filemack.com/tf_RGtEhDrnlTMHsSKO
[suprafiles] => https://www.filemack.com/sf_vm4g0FuRwXlxbBsP
)

)

关于php - 使用 file_get_contents 下载内容然后删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774216/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com