作法就是在HTTP的Content-Disposition欄位動手腳
就可以讓瀏覽器下載檔案
例如你希望瀏覽器直接下載jpg檔,而不是在瀏覽器上看到jpg檔,則php程式碼如下:
<?php
$filename = 'yui.jpg';
header("Content-type: image/jpeg");
header("Content-Disposition: attachment; filename=$filename");
readfile($filename);
?>
接著再把檔案存成xxx.php
當瀏覽器打開xxx.php,就會自動下載yui.jpg
2011年10月24日 星期一
2011年5月23日 星期一
用PHP發HTTP request
透過PHP cURL就可以做到( http://tw.php.net/curl )
這邊有個自動發plurk的範例程式碼:
http://gist.github.com/53380
這邊有個自動發plurk的範例程式碼:
http://gist.github.com/53380
<?phpdefine('NICKNAME', 'abc');define('PASSWORD', 'iamabc');define('USER_ID', '123456');$message = 'Hello World!';$ch = curl_init();curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');// logincurl_setopt($ch, CURLOPT_URL, 'http://www.plurk.com/Users/login');curl_setopt($ch, CURLOPT_POSTFIELDS, 'nick_name='.NICKNAME.'&password='.PASSWORD);curl_exec($ch);// postcurl_setopt($ch, CURLOPT_URL, 'http://www.plurk.com/TimeLine/addPlurk');curl_setopt($ch, CURLOPT_POSTFIELDS, 'qualifier=says&content='.urlencode($message).'&lang=tr_ch&no_comments=0&uid='.USER_ID);curl_exec($ch);curl_close($ch);?>
2011年5月21日 星期六
簡單的C++ HTTP library
http://www.codeproject.com/internet/amhttputils.asp
簡單使用如下
CAmHttpSocket http;
char* s = http.GetPage(_T("http://www.google.com.tw"));
cout<<s<<endl;
簡單使用如下
CAmHttpSocket http;
char* s = http.GetPage(_T("http://www.google.com.tw"));
cout<<s<<endl;
訂閱:
文章 (Atom)