3

CodeIgniterを使用して、フォームからいくつかのファイルをアップロードしています。「通常の」フォームエラー(required、valid_emailなど)を変換する方法は知っていますが、ファイルエラー(ファイルが許可されていない、ファイルが大きすぎるなど)を処理する方法がわかりません。

どのキーを使用する必要がありますか

$this->form_validation->set_message('KEY', 'TRANSLATION');

ありがとう

4

2 に答える 2

5

方法1

デフォルトでは、言語ファイルは通常、system/languageディレクトリに保存されます。upload_lang.phpまたは、フォルダ内にというファイルを作成して保存することもできますapplication/language

$lang['upload_userfile_not_set']        = "Unable to find a post variable called userfile.";
$lang['upload_file_exceeds_limit']      = "The uploaded file exceeds the maximum allowed size in your PHP configuration file.";
$lang['upload_file_exceeds_form_limit'] = "The uploaded file exceeds the maximum size allowed by the submission form.";
$lang['upload_file_partial']            = "The file was only partially uploaded.";
$lang['upload_no_temp_directory']       = "The temporary folder is missing.";
$lang['upload_unable_to_write_file']    = "The file could not be written to disk.";
$lang['upload_stopped_by_extension']    = "The file upload was stopped by extension.";
$lang['upload_no_file_selected']        = "You did not select a file to upload.";
$lang['upload_invalid_filetype']        = "The filetype you are attempting to upload is not allowed.";
$lang['upload_invalid_filesize']        = "The file you are attempting to upload is larger than the permitted size.";
$lang['upload_invalid_dimensions']      = "The image you are attempting to upload exceedes the maximum height or width.";
$lang['upload_destination_error']       = "A problem was encountered while attempting to move the uploaded file to the final destination.";
$lang['upload_no_filepath']             = "The upload path does not appear to be valid.";
$lang['upload_no_file_types']           = "You have not specified any allowed file types.";
$lang['upload_bad_filename']            = "The file name you submitted already exists on the server.";
$lang['upload_not_writable']            = "The upload destination folder does not appear to be writable.";

方法2

アップロードプロセス後にFlashdataを使用できます。

if ($this->upload->do_upload())
{
    $this->session->set_flashdata('success', 'Yep! Upload complete');
    redirect('go_back_home');
}
else
{
    $this->session->set_flashdata('error', 'Uh, upload not complete! The problem is..'); // Manually check
    redirect('go_back_form');
}

で問題を確認することもできます$this->upload->data()。これは、アップロードしたファイルに関連するすべてのデータを含む配列を返すヘルパー関数です。アレイのプロトタイプは次のとおりです。

Array
(
    [file_name]    => mypic.jpg
    [file_type]    => image/jpeg
    [file_path]    => /path/to/your/upload/
    [full_path]    => /path/to/your/upload/jpg.jpg
    [raw_name]     => mypic
    [orig_name]    => mypic.jpg
    [client_name]  => mypic.jpg
    [file_ext]     => .jpg
    [file_size]    => 22.2
    [is_image]     => 1
    [image_width]  => 800
    [image_height] => 600
    [image_type]   => jpeg
    [image_size_str] => width="800" height="200"
)
于 2012-06-20T13:58:20.677 に答える
-1

これを試して:

lang:your_translation_key

実際の例:

$this->form_validation->set_rules('name', 'lang:web_name', 'required|trim|xss_clean|min_length[2]|max_length[100]');
于 2012-06-18T17:05:04.730 に答える