gpt4 book ai didi

codeigniter - 如何翻译 CodeIgniter 上的上传错误

转载 作者:行者123 更新时间:2023-12-04 03:11:11 26 4
gpt4 key购买 nike

我正在使用 CodeIgniter 通过表单上传一些文件。我知道如何翻译“常规”表单错误(必填、valid_email 等),但我不知道如何处理文件错误(文件不允许、文件太大等)。

我应该使用哪些键

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

?

谢谢

最佳答案

方法一

默认情况下,language文件通常存储在 system/language 目录中。或者,您可以在 application/language 文件夹中创建一个名为 upload_lang.php 的文件,并将它们存储在那里。

$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.";

方法二

您可以使用 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() 检查问题。 This is a helper function返回一个数组,其中包含与您上传的文件相关的所有数据。这是数组原型(prototype):

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"
)

关于codeigniter - 如何翻译 CodeIgniter 上的上传错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11086214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com