2008年5月26日星期一
2008年5月25日星期日
ThinkPHP + UML
1. argouml
http://argouml.tigris.org/index.html
2. http://www.cnblogs.com/westsourcer/archive/2007/06/05/umltools.html
3. http://www.techq.com/blogdigest/46796.shtml
例子: PHP 非法词语/非法html代码过滤器.
1. http://blog.sina.com.cn/s/reader_484583ca01000bd5.html
2. http://www.21andy.com/blog/20070107/508.html
3. http://webservices.ctocio.com.cn/tips/52/7663552.shtml
4. http://club.21php.com/showthread.php?t=16058
Xpath语法,用于解释 XMI文件
http://www.wzsky.net/html/Program/Xml/90816.html
http://argouml.tigris.org/index.html
2. http://www.cnblogs.com/westsourcer/archive/2007/06/05/umltools.html
3. http://www.techq.com/blogdigest/46796.shtml
例子: PHP 非法词语/非法html代码过滤器.
1. http://blog.sina.com.cn/s/reader_484583ca01000bd5.html
2. http://www.21andy.com/blog/20070107/508.html
3. http://webservices.ctocio.com.cn/tips/52/7663552.shtml
4. http://club.21php.com/showthread.php?t=16058
Xpath语法,用于解释 XMI文件
http://www.wzsky.net/html/Program/Xml/90816.html
2008年5月24日星期六
win2003服务器iis+php+mysql安装
1.下载软件
mysql
-- http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51a-win32.zip/from/http://mysql.orst.edu/
apache
-- http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.2.8-win32-x86-openssl-0.9.8g.msi
php
-- http://cn2.php.net/get/php-5.2.5-Win32.zip/from/this/mirror
pecl
-- http://cn2.php.net/get/pecl-5.2.5-Win32.zip/from/this/mirror
phpAdmin
-- http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.11.5-all-languages-utf-8-only.tar.gz?download
cronolog
-- http://cronolog.org/download/cronolog-1.6.1-win32.zip
2. 安装
mysql
-- http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.51a-win32.zip/from/http://mysql.orst.edu/
apache
-- http://apache.mirror.phpchina.com/httpd/binaries/win32/apache_2.2.8-win32-x86-openssl-0.9.8g.msi
php
-- http://cn2.php.net/get/php-5.2.5-Win32.zip/from/this/mirror
pecl
-- http://cn2.php.net/get/pecl-5.2.5-Win32.zip/from/this/mirror
phpAdmin
-- http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.11.5-all-languages-utf-8-only.tar.gz?download
cronolog
-- http://cronolog.org/download/cronolog-1.6.1-win32.zip
2. 安装
2008年5月22日星期四
2008年5月20日星期二
ThinkASP MVC
-- 如何动态调用? Server.Execute and Execute
让你了解ASP中Server.Execute()及Execute的用法
首先说明一下,Server.Execute()和Execute是不同的,前者是ASP内置对象,后者是VB语句。
1.执行过程
Dim strSubName
strSubName="Print"
Execute strSubName
Sub Print()
Response.Write Now
End Sub
2.执行带参数的过程
Dim strSubName
strSubName="Print("""&Now&""")"
Execute strSubName
Sub Print(str)
Response.Write str
End Sub
3.动态包含文件
Server.Execute("xxx.asp")
server 是 ASP 中的一个内置对象,server.Execute 有一个方法为 Execute。
用法是:server.Execute(path)
它和 include 包含文件的功能很相似,不同之处是“包含文件”与“被包含文件”之间在变量和函数上是相互隔绝的。
比如两个页面文件:
a.asp
<%
dim c
c = "1"
response.Write(c)
server.Execute("b.asp")
response.Write(c)
%>
b.asp
<%
dim c
c = "2"
response.Write(c)
%>
显示结果为:121
两个页面都定义了变量 c,但不会报错说名称重定义,因为两个文件之间在变量和函数上是相互隔绝的,但如果在 a.asp 中是使用 include 包含 b.asp,便会报错说名称重定义。
注意:b.asp 同样可以“享用”客户端通过 POST 或 GET 提交给 a.asp 的值。
server.Execute 也可以形成递归,但递归达到一定的次数后不会像 server.Transfer 一样自动终止,而是报错并终止。
模板的实现参考
http://www.jb51.net/article/22.htm
思路:asp文件进行常规的逻辑处理,运算, 不用管显示层,当然需要显示的变量需要和显示层结合(PHP也一样),在模板文件中用<%%>直接控制变量的显示和逻辑的控制,不显示的逻辑控制符用html注释符注释掉,当然,不注释也是可以的.这样在ASP文件的最后""就实现了模板和ASP文件的结合,实现了代码和表现层的分离,这里并没有用ASP去Load模板,然后替换,浪费不必要ASP资源.这些处理全部都省去了。你会发现写ASP文件变得更加方便,因为你再也不需要在其中控制替换,逻辑显示的行为。在 ASP中直接执行肯定比替换要来得迅速和稳定.况且,加载模板的时候你必须还要加载一个组件.
写到这里,你也许明白了这种模板的精髓了,它只是一种设计模式,不是一个用模板类来处理的模板引擎。
让你了解ASP中Server.Execute()及Execute的用法
首先说明一下,Server.Execute()和Execute是不同的,前者是ASP内置对象,后者是VB语句。
1.执行过程
Dim strSubName
strSubName="Print"
Execute strSubName
Sub Print()
Response.Write Now
End Sub
2.执行带参数的过程
Dim strSubName
strSubName="Print("""&Now&""")"
Execute strSubName
Sub Print(str)
Response.Write str
End Sub
3.动态包含文件
Server.Execute("xxx.asp")
server 是 ASP 中的一个内置对象,server.Execute 有一个方法为 Execute。
用法是:server.Execute(path)
它和 include 包含文件的功能很相似,不同之处是“包含文件”与“被包含文件”之间在变量和函数上是相互隔绝的。
比如两个页面文件:
a.asp
<%
dim c
c = "1"
response.Write(c)
server.Execute("b.asp")
response.Write(c)
%>
b.asp
<%
dim c
c = "2"
response.Write(c)
%>
显示结果为:121
两个页面都定义了变量 c,但不会报错说名称重定义,因为两个文件之间在变量和函数上是相互隔绝的,但如果在 a.asp 中是使用 include 包含 b.asp,便会报错说名称重定义。
注意:b.asp 同样可以“享用”客户端通过 POST 或 GET 提交给 a.asp 的值。
server.Execute 也可以形成递归,但递归达到一定的次数后不会像 server.Transfer 一样自动终止,而是报错并终止。
模板的实现参考
http://www.jb51.net/article/22.htm
思路:asp文件进行常规的逻辑处理,运算, 不用管显示层,当然需要显示的变量需要和显示层结合(PHP也一样),在模板文件中用<%%>直接控制变量的显示和逻辑的控制,不显示的逻辑控制符用html注释符注释掉,当然,不注释也是可以的.这样在ASP文件的最后""就实现了模板和ASP文件的结合,实现了代码和表现层的分离,这里并没有用ASP去Load模板,然后替换,浪费不必要ASP资源.这些处理全部都省去了。你会发现写ASP文件变得更加方便,因为你再也不需要在其中控制替换,逻辑显示的行为。在 ASP中直接执行肯定比替换要来得迅速和稳定.况且,加载模板的时候你必须还要加载一个组件.
写到这里,你也许明白了这种模板的精髓了,它只是一种设计模式,不是一个用模板类来处理的模板引擎。
Hosting the ASP.NET runtime in your own application
http://www.microsoft.com/belux/msdn/nl/community/columns/desmet/hostaspnet2.mspx
http://book.xker.com/csdn/asppost1/web15748.htm
http://blogs.msdn.com/dmitryr/archive/2006/03/09/548131.aspx
http://blog.blueshop.com.tw/uni2tw/archive/2007/01/16/49267.aspx
http://www.z6688.com/info/32256-1.htm
http://book.xker.com/csdn/asppost1/web15748.htm
http://blogs.msdn.com/dmitryr/archive/2006/03/09/548131.aspx
http://blog.blueshop.com.tw/uni2tw/archive/2007/01/16/49267.aspx
http://www.z6688.com/info/32256-1.htm
2008年5月19日星期一
classic asp mvc framework
ASP Xtreme Evolution - A VBScript ASP 3.0 MVC Framework
Troika.ASP - A JScript ASP 3.0 MVC Framework
Simple MVC ASP Framework
Troika.ASP - A JScript ASP 3.0 MVC Framework
Simple MVC ASP Framework
2008年5月8日星期四
box.net文件下载
http://www.box.net
$previewUrl = 'http://www.box.net/shared/'.$_REQUEST['k'];
// Define a context for HTTP.
$aContext = array(
'http' => array(
'proxy' => 'tcp://127.0.0.1:5865', // This needs to be the server and the port of the NTLM Authentication Proxy Server.
'request_fulluri' => True,
),
);
$cxContext = stream_context_create($aContext);
// Now all file stream functions can use this context.
$result = file_get_contents($previewUrl, False, $cxContext);
//$result = file_get_contents($previewUrl);
?>
//get the file name
//var name = '01sdmbhjs01.jar';
$fond = ereg("var name = '([^']+)';", $result, $matchResult);
?>
$theLinkPre = "http://www.box.net/index.php";
$links = "";
$theLink = "";
$html = new DOMDocument();
//@$html->loadHTMLFile($url); // fetch the remote HTML file and parse it (@ suppresses warnings).
@$html -> loadHTML($result);
$xml = simplexml_import_dom($html); // convert the DOM object to a SimpleXML object.
foreach ($xml->xpath('//a') as $node){ // run an XPath query and iterate through the array of results
//print (string) $node . "\n"; // casting to string produces the text contents of the node.
//print $node['href'] . "\n"; // attributes of the node are accessible as array attributes.
//print $node->asXML() . "\n\n"; // asXML() produces the whole XML string.
$links .= $node['href'] . " \n";
if(0==strncmp($node['href'],$theLinkPre ,strlen($theLinkPre ))){
$theLink = $node['href'];
}
}
?>
header('Content-Type: application/octet-stream');
?>
$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1");
curl_setopt($ch, CURLOPT_PROXYPORT, 5865);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
//curl_setopt($ch, CURLOPT_POST, 1); //set how many paramaters to post
curl_setopt($ch, CURLOPT_URL,$previewUrl); //set the url we want to use
//curl_setopt($ch, CURLOPT_POSTFIELDS,$loginfields); //set the user_name field to 'joeyjohns'
$previewResult= curl_exec ($ch); //execute and get the results
curl_close ($ch);
//print $result; //display the reuslt
?>
$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1");
curl_setopt($ch, CURLOPT_PROXYPORT, 5865);
//$header = array();
//$header[] = 'Content-Type: application/force-download';
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
//curl_setopt($ch, CURLOPT_POST, 1); //set how many paramaters to post
curl_setopt($ch, CURLOPT_URL,$theLink); //set the url we want to use
//curl_setopt($ch, CURLOPT_POSTFIELDS,$loginfields); //set the user_name field to 'joeyjohns'
$contentResult = "";
$contentResult= curl_exec ($ch); //execute and get the results
curl_close ($ch);
//print $result; //display the reuslt
$contentResult = "";
?>
$previewUrl = 'http://www.box.net/shared/'.$_REQUEST['k'];
// Define a context for HTTP.
$aContext = array(
'http' => array(
'proxy' => 'tcp://127.0.0.1:5865', // This needs to be the server and the port of the NTLM Authentication Proxy Server.
'request_fulluri' => True,
),
);
$cxContext = stream_context_create($aContext);
// Now all file stream functions can use this context.
$result = file_get_contents($previewUrl, False, $cxContext);
//$result = file_get_contents($previewUrl);
?>
//get the file name
//var name = '01sdmbhjs01.jar';
$fond = ereg("var name = '([^']+)';", $result, $matchResult);
?>
$theLinkPre = "http://www.box.net/index.php";
$links = "";
$theLink = "";
$html = new DOMDocument();
//@$html->loadHTMLFile($url); // fetch the remote HTML file and parse it (@ suppresses warnings).
@$html -> loadHTML($result);
$xml = simplexml_import_dom($html); // convert the DOM object to a SimpleXML object.
foreach ($xml->xpath('//a') as $node){ // run an XPath query and iterate through the array of results
//print (string) $node . "\n"; // casting to string produces the text contents of the node.
//print $node['href'] . "\n"; // attributes of the node are accessible as array attributes.
//print $node->asXML() . "\n\n"; // asXML() produces the whole XML string.
$links .= $node['href'] . " \n";
if(0==strncmp($node['href'],$theLinkPre ,strlen($theLinkPre ))){
$theLink = $node['href'];
}
}
?>
header('Content-Type: application/octet-stream');
?>
$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1");
curl_setopt($ch, CURLOPT_PROXYPORT, 5865);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
//curl_setopt($ch, CURLOPT_POST, 1); //set how many paramaters to post
curl_setopt($ch, CURLOPT_URL,$previewUrl); //set the url we want to use
//curl_setopt($ch, CURLOPT_POSTFIELDS,$loginfields); //set the user_name field to 'joeyjohns'
$previewResult= curl_exec ($ch); //execute and get the results
curl_close ($ch);
//print $result; //display the reuslt
?>
$useragent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
$ch = curl_init();
//you might need to set some cookie details up (depending on the site)
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookies.txt");
curl_setopt($ch, CURLOPT_PROXY, "127.0.0.1");
curl_setopt($ch, CURLOPT_PROXYPORT, 5865);
//$header = array();
//$header[] = 'Content-Type: application/force-download';
//curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //set our user agent
//curl_setopt($ch, CURLOPT_POST, 1); //set how many paramaters to post
curl_setopt($ch, CURLOPT_URL,$theLink); //set the url we want to use
//curl_setopt($ch, CURLOPT_POSTFIELDS,$loginfields); //set the user_name field to 'joeyjohns'
$contentResult = "";
$contentResult= curl_exec ($ch); //execute and get the results
curl_close ($ch);
//print $result; //display the reuslt
$contentResult = "";
?>
CURL, Client URL Library Functions
http://www.zhaipeng.cn/manual/php/php_manaul_zh_html/ref.curl.html
PHP header() examples -完整代码
1. 2. /*** Function: PHP header() examples (PHP)
3. ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
4. ** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>.
5. ** Author: Jonas John
6. */
7.
8. // fix 404 pages:
9. header('HTTP/1.1 200 OK');
10.
11. // set 404 header:
12. header('HTTP/1.1 404 Not Found');
13.
14. // set Moved Permanently header (good for redrictions)
15. // use with location header
16. header('HTTP/1.1 301 Moved Permanently');
17.
18. // redirect to a new location:
19. header('Location: http://www.example.org/');
20.
21. // redrict with delay:
22. header('Refresh: 10; url=http://www.example.org/');
23. print 'You will be redirected in 10 seconds';
24.
25. // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />
26.
27. // override X-Powered-By: PHP:
28. header('X-Powered-By: PHP/4.4.0');
29. header('X-Powered-By: Brain/0.6b');
30.
31. // content language (en = English)
32. header('Content-language: en');
33.
34. // last modified (good for caching)
35. $time = time() - 60; // or filemtime($fn), etc
36. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
37.
38. // header for telling the browser that the content
39. // did not get changed
40. header('HTTP/1.1 304 Not Modified');
41.
42. // set content length (good for caching):
43. header('Content-Length: 1234');
44.
45. // Headers for an download:
46. header('Content-Type: application/octet-stream');
47. header('Content-Disposition: attachment; filename="example.zip"');
48. header('Content-Transfer-Encoding: binary');
49.
50. // load the file to send:readfile('example.zip');
51. // Disable caching of the current document:
52. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
53. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
54. // Date in the pastheader('Pragma: no-cache');
55. // set content type:
56. header('Content-Type: text/html; charset=iso-8859-1');
57. header('Content-Type: text/html; charset=utf-8');
58. header('Content-Type: text/plain');
59.
60. // plain text file
61. header('Content-Type: image/jpeg');
62.
63. // JPG picture
64. header('Content-Type: application/zip');
65.
66. // ZIP file
67. header('Content-Type: application/pdf');
68.
69. // PDF file
70. header('Content-Type: audio/mpeg');
71.
72. // Audio MPEG (MP3,...) file
73. header('Content-Type: application/x-shockwave-flash');
74.
75. // Flash animation// show sign in box
76. header('HTTP/1.1 401 Unauthorized');
77. header('WWW-Authenticate: Basic realm="Top Secret"');
78. print 'Text that will be displayed if the user hits cancel or ';
79. print 'enters wrong login data';?>
3. ** Desc: Some examples on how to use the header() function of PHPYou find a detailed tutorial at expertsrt.com (English) or at ffm.junetz.de (German).These is also a good help about caching at web-caching.com.
4. ** Example: see below. <br/><br/><b>Tip:</b> You can use these sites to check your headers: <a href="http://web-sniffer.net/">web-sniffer.net</a>, <a href="http://www.delorie.com/web/headers.html">delorie.com</a> or <a href="http://www.forret.com/projects/analyze/">www.forret.com</a>.
5. ** Author: Jonas John
6. */
7.
8. // fix 404 pages:
9. header('HTTP/1.1 200 OK');
10.
11. // set 404 header:
12. header('HTTP/1.1 404 Not Found');
13.
14. // set Moved Permanently header (good for redrictions)
15. // use with location header
16. header('HTTP/1.1 301 Moved Permanently');
17.
18. // redirect to a new location:
19. header('Location: http://www.example.org/');
20.
21. // redrict with delay:
22. header('Refresh: 10; url=http://www.example.org/');
23. print 'You will be redirected in 10 seconds';
24.
25. // you could also use the HTML syntax:// <meta http-equiv="refresh" content="10;http://www.example.org/ />
26.
27. // override X-Powered-By: PHP:
28. header('X-Powered-By: PHP/4.4.0');
29. header('X-Powered-By: Brain/0.6b');
30.
31. // content language (en = English)
32. header('Content-language: en');
33.
34. // last modified (good for caching)
35. $time = time() - 60; // or filemtime($fn), etc
36. header('Last-Modified: '.gmdate('D, d M Y H:i:s', $time).' GMT');
37.
38. // header for telling the browser that the content
39. // did not get changed
40. header('HTTP/1.1 304 Not Modified');
41.
42. // set content length (good for caching):
43. header('Content-Length: 1234');
44.
45. // Headers for an download:
46. header('Content-Type: application/octet-stream');
47. header('Content-Disposition: attachment; filename="example.zip"');
48. header('Content-Transfer-Encoding: binary');
49.
50. // load the file to send:readfile('example.zip');
51. // Disable caching of the current document:
52. header('Cache-Control: no-cache, no-store, max-age=0, must-revalidate');
53. header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
54. // Date in the pastheader('Pragma: no-cache');
55. // set content type:
56. header('Content-Type: text/html; charset=iso-8859-1');
57. header('Content-Type: text/html; charset=utf-8');
58. header('Content-Type: text/plain');
59.
60. // plain text file
61. header('Content-Type: image/jpeg');
62.
63. // JPG picture
64. header('Content-Type: application/zip');
65.
66. // ZIP file
67. header('Content-Type: application/pdf');
68.
69. // PDF file
70. header('Content-Type: audio/mpeg');
71.
72. // Audio MPEG (MP3,...) file
73. header('Content-Type: application/x-shockwave-flash');
74.
75. // Flash animation// show sign in box
76. header('HTTP/1.1 401 Unauthorized');
77. header('WWW-Authenticate: Basic realm="Top Secret"');
78. print 'Text that will be displayed if the user hits cancel or ';
79. print 'enters wrong login data';?>
php实现文件下载
最近在研究php实现文件下载的问题,按道理来说,一般的文件下载很简单,建立一个链接指向到目标文件就可以了,但是这样就直接暴露了文件所在路径,给盗链者打开了大门,并且可能会有安全隐患,一般来说,要实现安全的文件下载,在php下一般是利用header和fread这么来做的:
第一步
假设你要下载的是一个torrent的文件,那么先建立一个动态php文件,用户点击下载文件的时候直接链接到这个php并传回与文件位置相关的参数以帮助这个php能从数据库中取出文件所在的真实位置;这样做的另外一个好处是,可以通过这个php来对下载进行统计计数;这个过程并不难,所以就不写代码了,主要是对数据库的查询,假设文件的真实位置是$fileAdd,文件名为$fileName;
第二步
得到文件所在的真实位置以后,有人会用header的location直接重定向到这个文件,但是这样仍然是不安全的,因为某些下载软件还是可以通过重定向分析获得你的文件位置信息,因此需要用另外一种方法,就是php的文件处理API函数,这里主要是运用fread函数把文件直接吐给浏览器,让浏览器提示用户下载,所有的这些处理都是在服务器端完成的,因此用户是不会知道文件具体位置信息的,具体代码如下:
Header(”content-type:application/octet-stream”);
Header(”content-disposition:attatchment;filename:”.$fileName.”.torrent”);
if(file_exists($fileAdd) && $file=fopen($fileAdd,”r”))//判断文件是否存在并打开
{
fread($file,filesize($fileAdd));//读取文件内容并吐给浏览器
fclose($file);
}
细心的朋友可能会发现为什么要在程序的前面加上一些header信息呢?
因为,这些信息是用来告诉apache和浏览器下载文件的相关信息的,第一个content-type是告诉apache我的文件MIME类型是文件流格式,如果你的apache配置里面把torrent的MIME类型设为了application/octet-stream(比如:add application/octet-stream .torrent),那么浏览器端就会知道这是一个torrent的文件并提示你下载,相反,如果apache没有做此类设置,浏览器将不会知道做如何处理而将此文件直接以文本形式打开,这就是为什么有时候文件下载的时候浏览器上会出现乱码了;
而第二个header发送的信息是用来告诉浏览器我的这个文件是可以当作附件被下载的,下载保存的名称为$fileName.torrent
第一步
假设你要下载的是一个torrent的文件,那么先建立一个动态php文件,用户点击下载文件的时候直接链接到这个php并传回与文件位置相关的参数以帮助这个php能从数据库中取出文件所在的真实位置;这样做的另外一个好处是,可以通过这个php来对下载进行统计计数;这个过程并不难,所以就不写代码了,主要是对数据库的查询,假设文件的真实位置是$fileAdd,文件名为$fileName;
第二步
得到文件所在的真实位置以后,有人会用header的location直接重定向到这个文件,但是这样仍然是不安全的,因为某些下载软件还是可以通过重定向分析获得你的文件位置信息,因此需要用另外一种方法,就是php的文件处理API函数,这里主要是运用fread函数把文件直接吐给浏览器,让浏览器提示用户下载,所有的这些处理都是在服务器端完成的,因此用户是不会知道文件具体位置信息的,具体代码如下:
Header(”content-type:application/octet-stream”);
Header(”content-disposition:attatchment;filename:”.$fileName.”.torrent”);
if(file_exists($fileAdd) && $file=fopen($fileAdd,”r”))//判断文件是否存在并打开
{
fread($file,filesize($fileAdd));//读取文件内容并吐给浏览器
fclose($file);
}
细心的朋友可能会发现为什么要在程序的前面加上一些header信息呢?
因为,这些信息是用来告诉apache和浏览器下载文件的相关信息的,第一个content-type是告诉apache我的文件MIME类型是文件流格式,如果你的apache配置里面把torrent的MIME类型设为了application/octet-stream(比如:add application/octet-stream .torrent),那么浏览器端就会知道这是一个torrent的文件并提示你下载,相反,如果apache没有做此类设置,浏览器将不会知道做如何处理而将此文件直接以文本形式打开,这就是为什么有时候文件下载的时候浏览器上会出现乱码了;
而第二个header发送的信息是用来告诉浏览器我的这个文件是可以当作附件被下载的,下载保存的名称为$fileName.torrent
2008年5月6日星期二
2008年5月4日星期日
注意mingw和SDL的编译问题
gcc test.c -lmingw32 -lSDLmain -lSDL
上面三个-l的编译顺序不能错.否则会遇到各种问题.在整合eclipse3.3时,找了很久才找到答案.
上面三个-l的编译顺序不能错.否则会遇到各种问题.在整合eclipse3.3时,找了很久才找到答案.
2008年5月3日星期六
订阅:
博文 (Atom)