I am using CodeIgniter to upload some files through a form. I know how to translate "regular" form errors (required, valid_email, etc) but I don't know how to do it with file errors (file is not allowed, file is too big, etc).
Which keys should I use in
$this->form_validation->set_message('KEY', 'TRANSLATION');
?
Thanks
METHOD 1
By default, language files are typically stored in system/language directory. Alternately you can create a file called upload_lang.php inside your application/language folder and store them there.
$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.";
METHOD 2
You can use Flashdata after upload process.
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');
}
You can also check the problem with $this->upload->data(). This is a helper function that returns an array containing all of the data related to the file you uploaded. Here is the array 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"
)
Try this:
lang:your_translation_key
A real example:
$this->form_validation->set_rules('name', 'lang:web_name', 'required|trim|xss_clean|min_length[2]|max_length[100]');
Related
I need to export a report saving it in PDF format. I created a button that submits to a new page, which performs the following piece of code:
APEX_UTIL.DOWNLOAD_PRINT_DOCUMENT (
p_file_name => 'myreport123',
p_content_disposition => 'attachment',
p_application_id => :APP_ID,
p_report_query_name => 'MY_REPORT_QUERY',
p_report_layout_name => 'MY_REPORT_LAYOUT',
p_report_layout_type => 'xsl-fo',
p_document_format => 'pdf'
)
;
MY_REPORT_QUERY and MY_REPORT_LAYOUT are defined in the shared components. When I press the button, it downloads a pdf file, but it looks empty or corrupted.
What could be wrong? Do I need to specify the print server? And what about the field APP_ID?
I can confirm that both the query and layout work when I download the report by directly redirecting the page to the url of MY_REPORT_QUERY.
Thanks in advance and best regards.
I really need help please. I have been on this for over 2 hours and I keep getting the same error.
if(request()->hasFile(‘profile_image’)){ $fullFileName = request()->file(‘profile_image’)
->getClientOriginalName();
$path = request()->file(‘profile_image’)->storeAs(‘profilePhotos’, $fullFileName);
}
Now in the create method:
$user = User::create([
‘userId’ => request(‘userId’),
‘email’ => request(‘email’),
‘name’ => request(‘name’),
‘password’ => Hash::make(request(‘password’)),
‘profile_image’ => $fullFileName,
]);
I keep getting the error below. Someone please help...thanks. Plus I have created Storage link multiple times and keep deleting and recreating.
fopen(C:\xampp\htdocs\bluway\storage\app\public\profilePhotos\avatar.jpg): failed to open stream. No such file or directory
I am trying to create a zip file including 2 text files and download it. Here is my code. $fda and $fwl are 2 array datas.
$dataZip = array(
'./downloads/fda.in' => $data1,
'./downloads/fwl.in' => $data2
);
$this->zip->add_data($dataZip);
$this->zip->archive('./downloads/files_backup.zip');
$this->zip->download('files_backup.zip');
But it always returns error as a wrongly formatted string and nothing is downloaded.
fda.in�X�n�0}�+�
Could anybody tell me where I was wrong?
I found out the solution. All I have to do is add ob_start(); in the open of the controller file.
ob_start();
$dataZip = array(
'./downloads/fda.in' => $fda,
'./downloads/fwl.in' => $fwl
);
$this->zip->add_data($dataZip);
$this->zip->archive('./downloads/files_backup.zip');
$this->zip->download('files_backup.zip');
I am trying to create a form that will upload files to AWS S3. I have searched all around for an answer but I am getting the error "TypeError at /upload can't convert Symbol into Integer"
Here is the block of code
post '/upload' do
s3 = AWS::S3.new(
:access_key_id => 'X',
:secret_access_key => 'X')
bucket = s3.buckets['X']
title = params['title']
desc = params['desc']
file = params['file'][:tempfile]
s3.buckets['indio'].objects[title].write(:file => file)
end
I get the error on the line
file = params['file'][:tempfile]
Can someone point out what I am doing wrong?
Typically the error can't convert Symbol into Integer hints to the fact that you are trying to access an array with a non-integer.
From this I suspect the params['file'] is an array or a string, and not whatever you think it is.
Find out exactly what you got in params['file'] and continue from there.
I need upload some big files(about 1Gb) into google drive.
I using google-api-client(ruby) version 0.5.0:
media = Google::APIClient::UploadIO.new(file_name, mimeType, original_name)
result = client.execute!(
:api_method => client.service.files.insert,
:body_object => file,
:media => media,
:parameters => {
'uploadType' => 'resumable',
'alt' => 'json'})
I expected that my client split big file on parts and upload these parts on drive.
But I see in logs, that client sending only ONE BIG chunk to drive.
Here is small log example:
Content-Length: "132447559"
Content-Range: "bytes 0-132447558/132447559"
How can I upload big files by chunks with google-api-client?
The intended usage is to try and upload the file in a single chunk. Overall, it's more efficient/faster that way. But there are cases where chunking is preferable, so if you need to chunk the upload for whatever reason, just set the chunk_size property:
media = Google::APIClient::UploadIO.new(file_name, mimeType, original_name)
media.chunk_size = 1000000 # 1mb chunks
result = client.execute!(....)
I'm using the API version 0.7.1, even though I know we're supposed to be using version 0.9 now, because the older version matches the Ruby examples on Google's documentation.
I had to do resort to uploading in chunks because I was getting errors in httpclient library complaining about the file size being too large to convert to integer!
Unfortunately, using #stevebazyl did not work for me as it only uploads the first chunk and then throws a TransmissionError. This seems to be in the google-api-ruby-client code, specifically, Google::APIClient class in the execute! method. It doesn't seem to be handling an HTTP status of 308, which is what a resumable upload returns when it needs the next chunk. I did this to the code:
when 200...300, 308
result
(See api_client.rb)
And use the #send_all method in the ResumableUpload class just like the sample code in the docs and it worked for me. So in addition to #stevebazyl code, I have:
media = Google::APIClient::UploadIO.new(opts[:file], 'video/*')
media.chunk_size = 499200000
videos_insert_response = client.execute!(
:api_method => youtube.videos.insert,
:body_object => body,
:media => media,
:parameters => {
:uploadType => 'resumable',
:part => body.keys.join(',')
}
)
videos_insert_response.resumable_upload.send_all(client)