Weil Jimmer's BlogWeil Jimmer's Blog


Category:Experience

Found 54 records. At Page 7 / 11.

利用 Flickr API 取得原始圖片網址

No Comments
-
更新於 2017-05-19 18:53:20

鑒於網站上的空間有限,存放圖片又非常不方便,存本站會耗費空間與流量,存外站就不會。而 Flickr 支持 1 TB 的免費圖片空間!還支援原圖外連,這對我來說,非常好用!

為了把外站同步相簿到本站,需要研讀一下 Flickr API ,請參考:
https://www.flickr.com/services/api/

由於本教學是不需要"簽發授權的",所以原圖只能是上傳者公開,才能取得,否則只能其他解析度的圖片。但拿不到原圖,基本上還是很高清的。

不然只能用Flickr的OAuth取得Token,不過太麻煩我就不講了。可以參考:
https://www.flickr.com/services/api/explore/flickr.photosets.getPhotos

必須要自己設定成公開,API才可以取得原始圖片。

第一步、要先建立應用程式,https://www.flickr.com/services/apps/create/apply/

隨便填一下資料後,可以取得 應用程式的 key 值與金鑰。

然後使用:http://idgettr.com/

輸入自己個人頁面網址,可以取得 自己的 User ID,長得像是: 123456789@N01。

接著用「程式」訪問 Flickr 的 API 特殊網址 (要記得變更網址 { } 大括號夾住部分):

API_KEY,USER_ID 請照上述步驟取得
https://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key={API_KEY}&user_id={USER_ID}&format=json

可以得到如下圖的頁面:這是JSON格式的資料。請尋找您要取得網址的相簿ID。(長得像是下圖橘色所示)

然後再用程式訪問

{API_KEY},{USER_ID},{PHOTOSET_ID}記得替換
https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key={API_KEY}&user_id={USER_ID}&photoset_id={PHOTOSET_ID}&extras=url_o&format=json

就可取得 原始 資料。

範例程式碼:

<textarea name="contents" id="contents" style="resize:vertical;height:150px;font-size:12pt;"></textarea>
<script type="text/javascript">
var http = new XMLHttpRequest("Microsoft.XMLHTTP");
var url_='https://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key={API_KEY}&user_id={USER_ID}&photoset_id={PHOTOSET_ID}&extras=url_o&format=json';
function connect(){
	http.onreadystatechange = function(){
		if (http.readyState==4){
			if (http.status==200){
				var str = http.responseText.toString();
				str = str.substring(14,str.length-1);
				var obj = JSON.parse(str);
				var html_code_to_load = "";
				for (var i=0;i<obj['photoset']['photo'].length;i++){
					html_code_to_load += obj['photoset']['photo'][i]['url_o'] + "\n";
				}
				document.getElementById('contents').innerHTML=html_code_to_load.substring(0,html_code_to_load.length-1);
			}else{
				//Connect Failed.
			}
		}
	}
	http.open("GET",url_,true);
	http.send();
}
connect();
</script>

By Weil Jimmer


This entry was posted in General, Experience, Functions, HTML, JS, XML By Weil Jimmer.

輕易的將 DOC (Word) 文件 轉檔 成 PDF (電子書) 格式 - 圖文教學

No Comments
-
更新於 2017-02-18 23:12:52

使用內建的 Office 即可做轉換!

第一步,開啟文件並點擊左上角的檔案。

然後選擇側欄的「匯出」,

接著點擊「建立PDF/XPS」的按鈕,

存檔!

就完成了轉換。


This entry was posted in Experience, Office By Weil Jimmer.

PHP string to html characters 字串轉HTML碼

No Comments
-
更新於 2016-01-11 20:09:41

緣由:

最近因為裝了PHP7的緣故,又加上有一點點的閒,故研究PHP這塊。尤其是運算耗時方面,因為我本身就是要測試PHP7可以快到何種地步。聽說是快20倍的樣子。

結果,到最後我反而開始寫程式碼,昨天修正BBcode檢查的函數,運行約一萬字的代碼,結果速度慢到極致,被我修改後,倒加速不少,總速度提升82倍,原本12.3秒,修正到0.15秒(如果僅比較檢查BBcode的函數,加快上萬倍。),後來遇上了這個轉HTMLcode的問題,原先寫得太慢了,這是我第三次修正!

//目前我寫的最快的版本。

function string_to_utf16_ascii_HTML_new2($str){
	$str=mb_convert_encoding($str, 'ucs-2', 'utf-8');
	for($i=0;$i<strlen($str);$i+=2){
		$str2.='&#'.str_pad((ord($str[$i])*256+ord($str[$i+1])),5,'0',STR_PAD_LEFT).';';
	}
	return $str2;
}

//稍慢的版本(舊版)

function string_to_utf16_ascii_HTML_new($str){
	for ($i=0;$i<strlen($str);$i++){
		$k=ord($str[$i]);
		if ($k >= 192 and $k <= 223){
			$k=$k-192;
			$k2=ord($str[$i+1])-128;
			$c=$c.'&#'.str_pad($k*64+$k2,5,'0',STR_PAD_LEFT).';';
		}elseif ($k >= 224 and $k <= 239){
			$k=$k-224;
			$k2=ord($str[$i+1])-128;
			$k3=ord($str[$i+2])-128;
			$c=$c.'&#'.str_pad($k*4096+$k2*64+$k3,5,'0',STR_PAD_LEFT).';';
		}elseif ($k >= 128 and $k <= 191){
		}else{
			$c=$c.'&#'.str_pad($k,5,'0',STR_PAD_LEFT).';';
		}
	}
	return $c;
}

//極慢的版本(初版)

function string_to_utf16_ascii_HTML($str){
	for ($i=0;$str[$i]!="";$i++){
		$b[]=ord($str[$i]);
	}
	$str2=',';
	for ($i=0;$str[$i]!="";$i++){
		$xa=str_pad(decbin($b[$i]),8,'0',STR_PAD_LEFT);
		if (substr($xa,0,3) == "110"){
			$xb=str_pad(decbin($b[$i+1]),8,'0',STR_PAD_LEFT);
			$xx1=substr($xa,3);
			$xx2=substr($xb,2);
			$c=$c.$str2.str_pad(bindec($xx1.$xx2),5,'0',STR_PAD_LEFT);
		}elseif (substr($xa,0,4) == "1110"){
			$xb=str_pad(decbin($b[$i+1]),8,'0',STR_PAD_LEFT);
			$xc=str_pad(decbin($b[$i+2]),8,'0',STR_PAD_LEFT);
			$xx1=substr($xa,3);
			$xx2=substr($xb,2);
			$xx3=substr($xc,2);
			$c=$c.$str2.str_pad(bindec($xx1.$xx2.$xx3),5,'0',STR_PAD_LEFT);
		}elseif (substr($xa,0,2) == "10"){
		}else{
			$c=$c.$str2.str_pad($b[$i],5,'0',STR_PAD_LEFT);
		}
	}
	return substr($c,1);
}

//將HTMLcode轉回UTF-8字串。

function utf16_ascii_HTML_to_string($str){
	return mb_convert_encoding($str, 'UTF-8', 'HTML-ENTITIES'); 
}

/********

使用方法:

*********

$str='這是測試123';
$encode_str=string_to_utf16_ascii_HTML_new2($str);
echo $encode_str;

//output:
//&#36889;&#26159;&#28204;&#35430;&#00049;&#00050;&#00051;
//以瀏覽器顯示,等同於「這是測試123」。

echo utf16_ascii_HTML_to_string($encode_str);

//output:
//這是測試123

*/

 


This entry was posted in General, Experience, Functions, Note, PHP By Weil Jimmer.

長時間網站掛掉的感覺

No Comments
-
發布於 2015-12-15 19:01:53

本站在一週前遭遇中國猛烈DDOS攻擊,導致網站下線。我真心很想罵服務商,不過因為是免費的,就不好意思開口,很想說不會搞主機還學別人開放服務,趕快回去讀書吧。

本站經過多重搬遷 從原本的 Nazuka 搬到 GoogieHost 再搬到 EcVps 又再次搬到 LionFree (不推薦使用),本次被攻擊也是 只有 LionFree 才有的情況,以往頂多是暫時無法訪問,所以我又搬遷了一次主機。

心情很差,網站Offline時,很多事情不方便,此外,也沒辦法向身邊人傳達訊息。

(免費的真的很差勁!凡事都要備份!)


This entry was posted in Experience, Mood By Weil Jimmer.

程式設計缺陷足以修改Header偽造IP

No Comments
-
更新於 2017-05-19 18:59:14

這其實是個老梗,很久以前就知道了。今天又突然想到,發篇文章好了。

很多網站上的程式教學都是錯誤的,取得IP方法用get Header 的 Client-IP 及 X-Forwarded-For

真的是禍害,Header是可以給用戶隨意變更的。

我修改了 Header 在網站上隨意搜尋 What is my ip ?。

結果大部分網站都有問題!

我怎麼改,網站就怎麼顯示,怎麼都對。如果今天我把Header改成<script>標籤,不就造成了XSS攻擊漏洞?改成SQL語法,造成SQL注入漏洞。

只是剛好想到,之前也沒發過類似的文章,補發。


This entry was posted in General, Experience, HTML, The Internet, PHP By Weil Jimmer.

最前頁 上一頁  1 2 3 4 5 6 7 8 9 10 11 /11 頁)下一頁 最終頁

Visitor Count

pop
nonenonenone

Note

不要和愚蠢的人發生爭執。

支持網路中立性.
Support Net Neutrality.

支持臺灣實施
無條件基本收入

歡迎前來本站。

Quotes

我一定會老。

我一定會病。

我一定會死。

人生終須一別。

我們是業的主人。

Search

Music

Life Counter

23065days



Breaths between now and when I die.

Blogging Journey

4692days

since our first blog post.

Words Quiz


Quotes

The strong do what they can and the weak suffer what they must.

Privacy is your right and ability to be yourself and express yourself without the fear that someone is looking over your shoulder and that you might be punished for being yourself, whatever that may be.

It is quality rather than quantity that matters.

I WANT Internet Freedom.

Reality made most of people lost their childishness.

Justice,Freedom,Knowledge.

Without music life would be a mistake.

Support/Donate

This site also need a little money to maintain operations, not entirely without any cost in the Internet. Your donations will be the best support and power of the site.
MethodBitcoin Address
bitcoin1gtuwCjjVVrNUHPGvW6nsuWGxSwygUv4x
buymeacoffee
Register in linode via invitation link and stay active for three months.Linode

Support The Zeitgeist Movement

The Zeitgeist Movement

The Lie We Live

The Lie We Live

The Questions We Never Ask

The Questions We Never Ask

Man

Man

THE EMPLOYMENT

Man

In The Fall

In The Fall

Categories

Android (8)

Announcement (4)

Arduino (2)

Bash (2)

C (3)

C# (5)

C++ (1)

Experience (54)

Flash (2)

Free (13)

Functions (36)

Games (13)

General (63)

Git (3)

HTML (7)

Java (13)

JS (7)

Mood (24)

NAS (2)

Note (34)

Office (1)

OpenWrt (6)

PHP (9)

Privacy (4)

Product (12)

Python (4)

Software (11)

The Internet (26)

Tools (16)

VB.NET (8)

VR (1)

WebHosting (7)

Wi-Fi (5)

XML (4)