wechat-emoticon icon indicating copy to clipboard operation
wechat-emoticon copied to clipboard

php版本下载

Open swumao opened this issue 8 years ago • 0 comments

<?php

define("CURRENT_PATH", dirname(__FILE__));

$jsonUrl = "https://raw.githubusercontent.com/spacelan/wechat-emoticon/master/emoticons.json";

$dirName = 'images';

if (!is_dir(CURRENT_PATH . '/' . $dirName)) {
	if (mkdir(CURRENT_PATH . '/' . $dirName) == true) {
        	echo $dirName . ' create success!' . PHP_EOL;
	} else {
        	echo $dirName . ' create failed!' . PHP_EOL;
		die;
	}
}

$urlList = json_decode(file_get_contents($jsonUrl), true);

if (!is_array($urlList)) {
	echo 'json file fetch failed!' . PHP_EOL;
	die;
}

foreach($urlList as $key=>$url) {
	$filename = CURRENT_PATH . '/' . $dirName . '/image_' . $key . '.gif';

	echo 'Info :' . $filename . ' downloading' . PHP_EOL;

        $fp = fopen($filename, 'w');

	if ($fp === false) {
		echo 'Notice: ' . $filename . ' Open failed!' . PHP_EOL;
		continue;
	}

	$ret = fwrite($fp, file_get_contents(($url['url'])));

	if ($ret === false) {
		echo 'Notice: ' . $filename . ' Write failed!' . PHP_EOL;
	}

	fclose($fp);
}

swumao avatar Jan 06 '17 10:01 swumao