简体   繁体   中英

Downloading content with file_get_contents then deleting after

Currently I found this site for music related tools that is very handy it offers a mirror for file hosts, and I am trying to download some MP3 with file_get_contents and delete it afterwards pushed to this file host mirror.

current code have is this..

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

Which will store the MP3 we're trying to gather, but after it saves this information I want it to run through the function on this file mirror we found API then delete the MP3 file from our tmp directory afterwards.

the site is 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
    )

)

只需使用unlink()

unlink('tmp/'.$name.'.mp3');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM