Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Wednesday, October 11, 2006

PHP: Uploading larger files than default PHP setting.

In php.ini, please change the following values to appropriate MB value:
upload_max_filesize - limit of PHP's allowable size per file.
post_max_size - total size of form data including the files uploaded.

Example:
upload_max_filesize = 5M
post_max_size = 80M


Restart Apache server everytime php.ini is changed.

Reminders
  • Upload directory must be writable.
  • Form enctype should be multipart/form-data

Monday, July 10, 2006

PHP: Half-byte Katakana conversion (Single-byte, Hankaku, 半角カタカナ)

mb_convert_kana() is not working for me so I found a neat php code that can convert Hankaku to Zenkaku katakana and vice versa. Also has character set conversion. It's called JCode. It's free without warranty. I've only tested jcode-LE for now.

This is the link for the one with UTF-8:
http://www.spencernetwork.org/jcode/

This is the light edition without UTF-8, only supports EUC-JP, Shift-JIS, ISO-2022-JP (JIS):
http://www.spencernetwork.org/jcode-LE/

Tuesday, May 02, 2006

PHP: Uploading SJIS files to EUC-JP charset

This is assuming that mb_string is installed. Use iconv for Windows

In php.ini:

[mbstring]
; language for internal character representation.
mbstring.language = Japanese

; internal/script encoding.
; Some encoding cannot work as internal encoding.
; (e.g. SJIS, BIG5, ISO-2022-*)
mbstring.internal_encoding = EUC-JP

; http input encoding.
mbstring.http_input = auto

; http output encoding. mb_output_handler must be
; registered as output buffer to function
mbstring.http_output = EUC-JP

; enable automatic encoding translation accoding to
; mbstring.internal_encoding setting. Input chars are
; converted to internal encoding by setting this to On.
; Note: Do _not_ use automatic encoding translation for
; portable libs/applications.
mbstring.encoding_translation = On

; automatic encoding detection order.
; auto means
;mbstring.detect_order = auto

; substitute_character used when character cannot be converted
; one from another
;mbstring.substitute_character = none;

; overload(replace) single byte functions by mbstring functions.
; mail(), ereg(), etc are overloaded by mb_send_mail(), mb_ereg(),
; etc. Possible values are 0,1,2,4 or combination of them.
; For example, 7 for overload everything.
; 0: No overload
; 1: Overload mail() function
; 2: Overload str*() functions
; 4: Overload ereg*() functions
;mbstring.func_overload = 0

In upload.php:

// Set encoding of iconv
iconv_set_encoding('internal_encoding', 'EUC-JP');
iconv_set_encoding('input_encoding', 'SJIS');
iconv_set_encoding('output_encoding', 'EUC-JP');

// Set linux local to japanese
setlocale(LC_ALL, 'ja_JP.EUC-JP');

// Read data from file one row at a time
while (($data = fgets($handle)) !== false) {

// Convert SJIS (or other charset) to EUC-JP
$dataWindows = trim(iconv(mb_detect_encoding($data), _CHARSET.'//TRANSLIT', $data));
$dataLinux = trim(mb_convert_encoding($data, 'EUC-JP', mb_detect_encoding($data)));

}


* Using PHP 5.0.3