用file_get_contents下载内容,然后在
问题描述:
之后删除
目前我发现这个网站的音乐相关工具非常方便,它提供了文件主机的镜像,我试图用file_get_contents下载一些MP3,然后将其删除,然后推送到此文件主机镜子。用file_get_contents下载内容,然后在
当前代码必须是这样的..
$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
)
)
是你的问题怎么删除该文件?或如何使用filemack API? –
@mistermartin我想推我的MP3到filemack API,然后删除后,我的服务器推动它的文件,但不理解如何做到这一点..只有CSS和HTML开发主要的东西.. –
你提供的链接给出了一个例子如何上传文件。 PHP使用['unlink'](http://php.net/unlink)删除文件。 –