การทำ URL ให้เป็นแบบลงท้ายด้วย html
มกราคม 19, 2010
ปัญหา
URL ดูแล้วไม่สื่อความหมาย
http://127.0.0.1/mytest/content.php?mod=Gallery
เป้าหมาย
URL ดูแล้วลงท้ายด้วย html
http://127.0.0.1/mytest/Gallery.html
วิธีการทำ
1. เข้าไปที่ apache httpd.conf แล้วเอา comment บรรทัดด้านล่างออก
LoadModule rewrite_module modules/mod_rewrite.so จากนั้น restart apache
2. โยนไฟล์ .htaccess ไปไว้ที่ DocumentRoot ของ apache เช่นที่
C:\AppServ\www\
ซึ่งเนื่อหาของไฟล์ .htaccess มีดังนี้
RewriteEngine On
RewriteBase /
rewriterule ^mytest/([^-]+)\.html$ /mytest/content.php?mod=$1 [L]
**หมายถึง เราสามารถเรียก URL http://127.0.0.1/mytest/content.php?mod=Gallery
ด้วย URL http://127.0.0.1/mytest/Gallery.html
3) restart apache
4) ทดลองเรียก URL http://127.0.0.1/mytest/Gallery.html
**site reference
http://www.php-learn-it.com/tutorials/mod_rewrite_dynamic_urls_to_static_urls.html
พระมหาวุฒิชัย (ว.วชิรเมธี) Woody เกิดมาคุย [4/4]
มกราคม 16, 2010
การแปลงข้อมูล XML ให้อยู่ในรูปแบบที่ดูง่ายด้วย XSL และ PHP
มกราคม 4, 2010
อาจารย์เขียนได้ชัดเจนมาก ผมขอเก็บลิ้งค์ไว้ใน blog ผมครับ
http://gotoknow.org/blog/xmlws/162186
ดึงเอกสารจากตารางใน RDBMS มาทำ Index ด้วย apache solr
มกราคม 2, 2010
แนวคิดคือจะดึงข้อมูลจากตารางที่เราต้องการมาทำ Index โดยตารางควรจะ Join กันเพื่อให้ได้เอกสารที่ต้องการแล้วส่งไปให้ apache solr
การตั้งค่าว่าจะไปดึงฐานข้อมูลที่ไหน และเอาจากตารางใดบ้างอยู่ที่ $SOLR_HOME/conf/data-config.xml
ตัวอย่างด้านล่างประกอบไปด้วย 2 เรื่องแต่ละเรื่องก็ จะต้อง query ด้วยคำสั่ง select (ผู้เขียนละไว้…..)
<dataConfig>
<dataSource type=”JdbcDataSource” driver=”com.mysql.jdbc.Driver” url=”jdbc:mysql://127.0.0.1/cms_fpo?useUnicode=true&characterEncoding=UTF-8″ user=”XXXXX” password=XXXXX”/>
<document name=”fpo”>
<!– fpo_content, fpo_category –>
<entity name=”fpocontent” query=”select …………………………………..”>
<field column=”contentID” name=”id”/>
<field column=”title” name=”name”/>
<field column=”detail” name=”features”/>
<field column=”link” name=”links”/>
<field column=”created_by” name=”created_by”/>
<field column=”source_name” name=”source_name”/>
<field column=”source_contact” name=”source_contact”/>
<field column=”cattitle” name=”cat”/>
</entity>
<!– fpo_gallery –>
<entity name=”fpogallery” query=”select ………………………………………….”>
<field column=”gallery_id” name=”id”/>
<field column=”gallery_name” name=”name”/>
<field column=”gallery_desc” name=”features”/>
<field column=”link” name=”links”/>
<field column=”created_by” name=”created_by”/>
<field column=”gallery_name” name=”cat”/>
</entity>
</document>
</dataConfig>
***หมายเหตุ จากการตั้งค่าด้านบน จะโหลดข้อมูลจาก mysql ด้วย mysql jdbc driver ดั้งนั้นอย่าลืมโยน jdbc mysql driver (mysql-connector-java-5.1.6-bin.jar) ไว้ที่ $CATALINA_HOME\webapps\solr\WEB-INF\lib เช่นที่
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\solr\WEB-INF\lib
***หมายเหตุ ถ้าข้อมูลเยอะๆ tomcat อาจจะเกิด OutofMemoryError ดังนั้นจะต้องปรับให้มีค่า heap space มากขึ้นดังภาพ
เมื่อตั้งค่าทุกอย่างเรียบร้อยให้ restart tomcat แล้วเรียกคำสั่ง
http://127.0.0.1:8080/solr/dataimport?command=full-import
เพื่อล้างและโหลดข้อมูลทำ Index ใหม่ทั้งหมดหรือถ้าต้องการจะเพียงแค่ update index เฉพาะส่วนที่ใหม่ๆเท่านั้นให้เรียก
http://127.0.0.1:8080/solr/dataimport?command=delta-import
ตั้ง apache solr ให้ตัดคำไทยได้
มกราคม 2, 2010
ถ้าเราไม่เปลี่ยนการตั้งค่าการตัดคำใดใน solr schema.xml (อยู่ใน $SOLR_HOME/conf) การตัดคำจะใช้ การเว้นวรรค
วิธีการคือ เข้าไปที่ $SOLR_HOME/conf/schema.xsml (เช่น C:\web\solr\conf\schema.xml)
แล้วเปลี่ยนช่วงที่เป็น
<fieldType name=”text” class=”solr.TextField”
positionIncrementGap=”100″>
……..
……..
</fieldType>
ให้เปลี่ยนเป็น
<fieldType name=”text” class=”solr.TextField”>
<analyzer type=”index” class=”org.apache.lucene.analysis.th.ThaiAnalyzer”/>
<analyzer type=”query” class=”org.apache.lucene.analysis.th.ThaiAnalyzer”/>
</fieldType>
จากนั้นก็ save แล้ว restart tomcat แล้วจัดการทำ index ใหม่หมด แล้วลอง search ด้วยคำภาษาไทยอีกครั้ง ผลการ search จะได้ผลลัพธ์การค้นหาออกมามากขึ้น
ลง apache solr บน tomcat
มกราคม 2, 2010
Tomcat on Windows
Single Solr app
1.Download and install Tomcat for Windows using the MSI installer. Install it with the tcnative.dll file. Say you installed it in c:\tomcat\
2. Check if Tomcat is installed correctly by going to http://localhost:8080/
3. Change the c:\tomcat\conf\server.xml file to add the URIEncoding Connector element as shown above.
——————————————–
If you are going to query Solr using international characters (>127) using HTTP-GET, you must configure Tomcat to conform to the URI standard by accepting percent-encoded UTF-8.
Edit Tomcat’s conf/server.xml and add the following attribute to the correct Connector element: URIEncoding=”UTF-8″.
<Server ...>
<Service ...>
<Connector ... URIEncoding="UTF-8"/>
...
</Connector>
</Service>
</Server>
ดังรูปด้านล่าง (ของผมให้ tomcat ทำงานที่ port 8000)

————————–
4. Download and unzip the Solr distribution zip file into (say) c:\temp\solrZip\
5. Make the “solr home” directory called, where you intend the application server to function, say c:\web\solr\
Copy the contents of the example\solr directory c:\temp\solrZip\example\solr\ to c:\web\solr\
6. Stop the Tomcat service
7. Copy the *solr*.war file from c:\temp\solrZip\dist\ to the Tomcat webapps directory c:\tomcat\webapps\
8. Rename the *solr*.war file solr.war
9. Configure Tomcat to recognise the solr home directory you created, by adding the Java Option -Dsolr.solr.home=c:\web\solr
either use the system tray icon to add the java option
or manually edit the environment script c:\tomcat\bin\setenv.bat and add it to JAVA_OPTS
ที่ผมทดลองทำ ใส่ -Dsolr.solr.home=c:\web\solr ที่ system tray icon
10. Start the Tomcat service
11. Go to the solr admin page to verify that the installation is working. It will be at http://localhost:8080/solr/admin
***อ้างอิง http://wiki.apache.org/solr/SolrTomcat
FCKEditor โดยมี pathเก็บไฟล์ ส่วนตัวของแต่ละคน
ธันวาคม 25, 2009
ในที่นี้ต้องมีระบบ Login อยู่ที่ระบบที่เราต้องการอยู่แล้ว
แก้ไขไฟล์ ……FPO\includes\fckeditor\editor\filemanager\connectors\php\config.php ให้ path เป็นดังนี้
<?php
session_start();
/*
* FCKeditor – The text editor for Internet – http://www.fckeditor.net
* Copyright (C) 2003-2008 Frederico Caldeira Knabben
*
* == BEGIN LICENSE ==
*
* Licensed under the terms of any of the following licenses at your
* choice:
*
* – GNU General Public License Version 2 or later (the “GPL”)
* http://www.gnu.org/licenses/gpl.html
*
* – GNU Lesser General Public License Version 2.1 or later (the “LGPL”)
* http://www.gnu.org/licenses/lgpl.html
*
* – Mozilla Public License Version 1.1 or later (the “MPL”)
* http://www.mozilla.org/MPL/MPL-1.1.html
*
* == END LICENSE ==
*
* Configuration file for the File Manager Connector for PHP.
*/
global $Config ;
// SECURITY: You must explicitly enable this “connector”. (Set it to “true”).
// WARNING: don’t just set “$Config['Enabled'] = true ;”, you must be sure that only
// authenticated users can access this file or use some kind of session checking.
$Config['Enabled'] = true;
// Path to user files relative to the document root.
$Config['UserFilesPath'] = ($_SESSION['FCKeditor']['UserFilesPath']==”")? ‘/FPO/member_profile/’ : $_SESSION['FCKeditor']['UserFilesPath'] ;
// Fill the following value it you prefer to specify the absolute path for the
// user files directory. Useful if you are using a virtual directory, symbolic
// link or alias. Examples: ‘C:\\MySite\\userfiles\\’ or ‘/root/mysite/userfiles/’.
// Attention: The above ‘UserFilesPath’ must point to the same directory.
$Config['UserFilesAbsolutePath'] = ” ;
// Due to security issues with Apache modules, it is recommended to leave the
// following setting enabled.
$Config['ForceSingleExtension'] = true ;
// Perform additional checks for image files.
// If set to true, validate image size (using getimagesize).
$Config['SecureImageUploads'] = true;
// What the user can do with this connector.
$Config['ConfigAllowedCommands'] = array(‘QuickUpload’, ‘FileUpload’, ‘GetFolders’, ‘GetFoldersAndFiles’, ‘CreateFolder’) ;
// Allowed Resource Types.
$Config['ConfigAllowedTypes'] = array(‘File’, ‘Image’, ‘Flash’, ‘Media’) ;
// For security, HTML is allowed in the first Kb of data for files having the
// following extensions only.
$Config['HtmlExtensions'] = array(“html”, “htm”, “xml”, “xsd”, “txt”, “js”) ;
// After file is uploaded, sometimes it is required to change its permissions
// so that it was possible to access it at the later time.
// If possible, it is recommended to set more restrictive permissions, like 0755.
// Set to 0 to disable this feature.
// Note: not needed on Windows-based servers.
$Config['ChmodOnUpload'] = 0777 ;
// See comments above.
// Used when creating folders that does not exist.
$Config['ChmodOnFolderCreate'] = 0777 ;
/*
Configuration settings for each Resource Type
- AllowedExtensions: the possible extensions that can be allowed.
If it is empty then any file type can be uploaded.
- DeniedExtensions: The extensions that won’t be allowed.
If it is empty then no restrictions are done here.
For a file to be uploaded it has to fulfill both the AllowedExtensions
and DeniedExtensions (that’s it: not being denied) conditions.
- FileTypesPath: the virtual folder relative to the document root where
these resources will be located.
Attention: It must start and end with a slash: ‘/’
- FileTypesAbsolutePath: the physical path to the above folder. It must be
an absolute path.
If it’s an empty string then it will be autocalculated.
Useful if you are using a virtual directory, symbolic link or alias.
Examples: ‘C:\\MySite\\userfiles\\’ or ‘/root/mysite/userfiles/’.
Attention: The above ‘FileTypesPath’ must point to the same directory.
Attention: It must end with a slash: ‘/’
- QuickUploadPath: the virtual folder relative to the document root where
these resources will be uploaded using the Upload tab in the resources
dialogs.
Attention: It must start and end with a slash: ‘/’
- QuickUploadAbsolutePath: the physical path to the above folder. It must be
an absolute path.
If it’s an empty string then it will be autocalculated.
Useful if you are using a virtual directory, symbolic link or alias.
Examples: ‘C:\\MySite\\userfiles\\’ or ‘/root/mysite/userfiles/’.
Attention: The above ‘QuickUploadPath’ must point to the same directory.
Attention: It must end with a slash: ‘/’
NOTE: by default, QuickUploadPath and QuickUploadAbsolutePath point to
“userfiles” directory to maintain backwards compatibility with older versions of FCKeditor.
This is fine, but you in some cases you will be not able to browse uploaded files using file browser.
Example: if you click on “image button”, select “Upload” tab and send image
to the server, image will appear in FCKeditor correctly, but because it is placed
directly in /userfiles/ directory, you’ll be not able to see it in built-in file browser.
The more expected behaviour would be to send images directly to “image” subfolder.
To achieve that, simply change
$Config['QuickUploadPath']['Image'] = $Config['UserFilesPath'] ;
$Config['QuickUploadAbsolutePath']['Image'] = $Config['UserFilesAbsolutePath'] ;
into:
$Config['QuickUploadPath']['Image'] = $Config['FileTypesPath']['Image'] ;
$Config['QuickUploadAbsolutePath']['Image'] = $Config['FileTypesAbsolutePath']['Image'] ;
*/
$Config['AllowedExtensions']['File'] = array(‘7z’, ‘aiff’, ‘asf’, ‘avi’, ‘bmp’, ‘csv’, ‘doc’, ‘fla’, ‘flv’, ‘gif’, ‘gz’, ‘gzip’, ‘jpeg’, ‘jpg’, ‘mid’, ‘mov’, ‘mp3′, ‘mp4′, ‘mpc’, ‘mpeg’, ‘mpg’, ‘ods’, ‘odt’, ‘pdf’, ‘png’, ‘ppt’, ‘pxd’, ‘qt’, ‘ram’, ‘rar’, ‘rm’, ‘rmi’, ‘rmvb’, ‘rtf’, ’sdc’, ’sitd’, ’swf’, ’sxc’, ’sxw’, ‘tar’, ‘tgz’, ‘tif’, ‘tiff’, ‘txt’, ‘vsd’, ‘wav’, ‘wma’, ‘wmv’, ‘xls’, ‘xml’, ‘zip’) ;
$Config['DeniedExtensions']['File'] = array() ;
$Config['FileTypesPath']['File'] = $Config['UserFilesPath'] . ‘file/’ ;
$Config['FileTypesAbsolutePath']['File']= ($Config['UserFilesAbsolutePath'] == ”) ? ” : $Config['UserFilesAbsolutePath'].’file/’ ;
$Config['QuickUploadPath']['File'] = $Config['UserFilesPath'] . ‘file/’ ;
$Config['QuickUploadAbsolutePath']['File']= $Config['UserFilesAbsolutePath'] ;
$Config['AllowedExtensions']['Image'] = array(‘bmp’,'gif’,'jpeg’,'jpg’,'png’) ;
$Config['DeniedExtensions']['Image'] = array() ;
$Config['FileTypesPath']['Image'] = $Config['UserFilesPath'] . ‘image/’ ;
$Config['FileTypesAbsolutePath']['Image']= ($Config['UserFilesAbsolutePath'] == ”) ? ” : $Config['UserFilesAbsolutePath'].’image/’ ;
$Config['QuickUploadPath']['Image'] = $Config['UserFilesPath'] . ‘image/’ ;
$Config['QuickUploadAbsolutePath']['Image']= $Config['UserFilesAbsolutePath'] ;
$Config['AllowedExtensions']['Flash'] = array(’swf’,'flv’) ;
$Config['DeniedExtensions']['Flash'] = array() ;
$Config['FileTypesPath']['Flash'] = $Config['UserFilesPath'] . ‘flash/’ ;
$Config['FileTypesAbsolutePath']['Flash']= ($Config['UserFilesAbsolutePath'] == ”) ? ” : $Config['UserFilesAbsolutePath'].’flash/’ ;
$Config['QuickUploadPath']['Flash'] = $Config['UserFilesPath'] . ‘flash/’ ;
$Config['QuickUploadAbsolutePath']['Flash']= $Config['UserFilesAbsolutePath'] ;
$Config['AllowedExtensions']['Media'] = array(‘aiff’, ‘asf’, ‘avi’, ‘bmp’, ‘fla’, ‘flv’, ‘gif’, ‘jpeg’, ‘jpg’, ‘mid’, ‘mov’, ‘mp3′, ‘mp4′, ‘mpc’, ‘mpeg’, ‘mpg’, ‘png’, ‘qt’, ‘ram’, ‘rm’, ‘rmi’, ‘rmvb’, ’swf’, ‘tif’, ‘tiff’, ‘wav’, ‘wma’, ‘wmv’) ;
$Config['DeniedExtensions']['Media'] = array() ;
$Config['FileTypesPath']['Media'] = $Config['UserFilesPath'] . ‘media/’ ;
$Config['FileTypesAbsolutePath']['Media']= ($Config['UserFilesAbsolutePath'] == ”) ? ” : $Config['UserFilesAbsolutePath'].’media/’ ;
$Config['QuickUploadPath']['Media'] = $Config['UserFilesPath'] . ‘media/’ ;
$Config['QuickUploadAbsolutePath']['Media']= $Config['UserFilesAbsolutePath'] ;
?>
เปลี่ยน config.php เพื่อให้เก็บไฟล์ที่แต่ละคนเก็บไว้ที่ /FPO/member_profile/ชื่อ user/… เช่น
/FPO/member_profile/junjao/…..
โดยแยกเก็บเป็นหมวดหมู่ย่อยดังนี้
/FPO/member_profile/junjao/file
/FPO/member_profile/junjao/image
/FPO/member_profile/junjao/flash
/FPO/member_profile/junjao/media
ทั้งนี้เราจะต้องเปลี่ยนค่า $_SESSION['FCKeditor']['UserFilesPath'] ของแต่ละคน ที่โปรแกรม php ในที่นี้ผมทำเป็นไฟล์ incFCK.php ไว้เพื่อ includes ในทุกๆ page ของ php ที่ต้องการเปิด FCKEditor
<?php
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
$_SESSION['FCKeditor']['UserFilesPath'] = “/FPO/member_profile/”.getUserNameFromSession().”/upload/”;
?>
โดย getUserNameFromSession() จะเป็นฟังก์ขั่นที่ได้ค่า username ออกมา (ได้มาจาก user คนนั้น Login แล้ว program php ของเราเก็บค่า username ของ user คนนั้นไว้ใน session
php readfile (default max size=24M)
พฤศจิกายน 18, 2009
เมื่อใช้ function readfile(); ใน php แต่ php.ini ตั้งไว้
memory_limit = 24M ; Maximum amount of memory a script may consume (8MB)
เมื่อไฟล์มีขนาดใหญ่มากเกิน 24M ไฟล์จะถูกตัดออก อ่านเข้ามาใน program ได้เพียง 24MB
วิธีการแก้ไข
แก้เป็น
max_execution_time = 1800 ; Maximum execution time of each script, in seconds
max_input_time = 1800; Maximum amount of time each script may spend parsing request data
memory_limit = 500M ; Maximum amount of memory a script may consume (8MB)
จากนั้นก็ restart apache
วิธีการตั้ง Task Scheduler ให้ไปเรียก HTTP Get PHP ในระบบOS Window
พฤศจิกายน 11, 2009
1). ที่ windows เปิด command prompt พิมพ์คำว่า php แล้วไม่ขึ้นคำว่า command not found แสดงว่า สามารถเรียก php.exe ผ่าน command prompt ได้ (ปกติแล้วลง Appserv ตัวโปรแกรม php.exe จะอยู่ที่ path C:\AppServ\php5)
2).ที่ windows เข้าไปที่ Administrative tools –> ดับเบิ้ลคลิกที่ Task Scheduler

3). คลิกขวาที่ Task Schedule Library แล้วเลือก Create Basic Task
จากนั้นใส่ชื่อ, เลือก Daily หากต้องการเรียก php รายวัน, เลือกเวลา และเลือก Start a program
4) ในช่อง Program/script ให้ Browse ไปที่ bat ไฟล์ที่เราสร้างไว้ตั้งแต่ต้น อย่างเช่นในตัวอย่างนี้สร้างไฟล์ชื่อ sscron.bat โดยเก็บไว้ที่ C:\Users\jun\ โดยเนื้อหาของ sscron.bat จะเป็นดังนี้
start php.exe C:\\AppServ\\www\\FPO\\modules\\Subscription\\sendmailforss.php
หมายถึงตัว Task Scheduler ของ Windows จะไปเรียกไฟล์ sendmailforss.php ด้วย php.exe

5). ขั้นตอนสุดท้าย กด Finish
6.) จะได้งานใหม่ขึ้นมาดังรูป

ให้ double click ที่งานนั้น

แล้วเลือกเป็น Run whether user is logged on or not เพราะ server อาจจะ Log off เมื่อหน้าจอนิ่ง แต่เราก็อยากให้งานที่เราตั้งไว้ทำงาน และเลือก Do not store password. The task will only have access to local computer resources ดังรูป จากนั้นกด OK
ไซต์อ้างอิง
http://www.devx.com/DevX/Article/39900/1763/page/3
Software Project management
พฤศจิกายน 1, 2009
วันนี้เรียน software project management สอนให้เรารู้ว่ามีเทคนิคต่างๆในการจัดการปัญหาเมื่อเจอปัญหา เช่นเมื่อคุยกับลูกค้า และการทำ software เป็นเรื่องยากที่จะประเมินเวลา ไม่เหมือนงานก่อสร้างที่ประเมินขนาดของานที่เหลือได้ชัดเจน

อาจารย์บอกว่า คนเราำทำอะไรก็ตามได้งานออกมาหนึ่งชิ้น และจะภูิมิใจตนเอง มีกำลังใจทำต่อไป สังเกตตัวเราเองก็ใช่เลย ถ้าวันไหนทำงานแล้วออกได้ 1 ชิ้นจะรู้สึกดีมีกำลังใจ แต่ถ้าวันไหน ไม่ได้งานเลยจะรู้สึกเบื่อๆ


