Lang sub folder detection codeigniter - codeigniter

In my lang load I would like to be able to try and make it so that if type admin then would pick up subfolder in admin and find the controller lang file. Same as what do with the glob.
How would that be possible for language load function?
Unable to load the requested language file:
language/english/admin/*/dashboard_lang.php
$files = glob(FCPATH . 'application/modules/admin/controllers/*/*.php');
if ($files) {
foreach ($files as $file) {
$controller = basename(strtolower($file), '.php');
$this->lang->load('admin/*'. $controller, 'english');
$data['controller_files'][] = array(
'controller' => $controller,
'install' => '',
'installed' => in_array($controller, $controller_files)
);
}
}

You could do something like this if you wanted to load a language file
in a subfolder with the same name as the "controller".
language/english/admin/dashboard/dashboard_lang.php
$controller = '';
$path = FCPATH . 'application/modules/admin/controllers/*/*.php';
$files = glob($path, GLOB_BRACE);
if(!$files || empty($files)){
log_message('error', "Unable to find any matches : $path");
}
foreach($files as $file){
$basename = basename(strtolower($file));
$pathinfo = pathinfo($basename);
$controller = $pathinfo['filename'];
$this->lang->load("admin/$controller/$controller", 'english');
$data['controller_files'][] = array(
'controller' => $controller,
'install' => '',
'installed' => in_array($controller, $controller_files)
);
}

Related

Change directory for uploading image

How can I change the directory of the uploaded images.
I want to upload it in the App/public/files folder.
My code here:
public function update(Request $request, Organigramme $organigramme)
{
$id = $organigramme->id;
$organigramme = Organigramme::find($id);
$organigramme->matricule = $request->input('matricule');
if ($request->has('profile_image'))
{
$image = $request->file('profile_image');
$name = str_slug($request->input('matricule'));
$folder = '/uploads/images/';
$filePath = $folder . $name. '.' . $image->getClientOriginalExtension();
$this->uploadOne($image, $folder, 'public', $name);
$organigramme->profile_image = $filePath;
$organigramme->save();
}
return view( 'admin.organigrammes.show', compact('organigramme'));
}
public function uploadOne(UploadedFile $uploadedFile, $folder = null, $disk = 'public', $filename = null)
{
$name = !is_null($filename) ? $filename : str_random(25);
$file = $uploadedFile->storeAs($folder, $name.'.'.$uploadedFile->getClientOriginalExtension(), $disk);
return $file;
}
In the config/filesystems file add a new save path.For example:
'images' => [
'driver' => 'local',
'root' => base_path().'/app/public/files',
],
In the code itself, use the following code to save:
Storage::disk('images')->put($path, $image);

updated image stores in database but not folder in laravel

problem is that company_photo stores in database but not store in company_photos folder, please tell me where i going wrong..
public function update(Request $request, Company $company,CompanyOtherInfo $CompanyOtherInfo )
{
//dd($company);
//dd(request()->all());
if($request->hasFile('company_photo')){
$files=public_path().'/company_photos/'.$req->input('company_photo1');
File::delete($files);
//dd($files);
$file = $req->file('company_photo');
$destinationPath = public_path().'/company_photos/';
$filename = $file->getClientOriginalName();
$file->move($destinationPath, $filename);
// echo $filename;
}
else{
$filename=$request->input('company_photo1');
}
//dd($request);
//dd($filename);
$company::where('companies.company_id',$company->company_id)
->update([
'company_photo' => $filename,
'company_name' => request('company_name'),
'company_email' => request('company_email'),
'company_mobile' => request('company_mobile'),
'company_country' => request('company_country'),
'company_state' => request('company_state'),
'company_city' => request('company_city'),
'company_pincode' => request('company_pincode'),
'company_address' => request('company_address'),
'industry_id' => request('industry_id'),
'segment_id' => request('segment_id'),
'company_code' => request('company_code'),
'contact_person'=>request('contact_person'),
]);
The issue you had is you changed the variable $request to $req half way through your code:
Change these lines:
$files = public_path().'/company_photos/'.$req->input('company_photo1');
$file = $req->file('company_photo');
to:
$files = public_path().'/company_photos/'.$request->input('company_photo1');
$file = $request->file('company_photo');
Here is the code with a little refactor:
$filename = $request->input('company_photo1');
if ($request->hasFile('company_photo')) {
$files = public_path().'/company_photos/'.$fileName;
File::delete($files);
$file = $request->file('company_photo');
$file->move(public_path().'/company_photos/', $file->getClientOriginalName());
}

Save multiple upload with clientOriginalName

hy everyone,, i want to upload multiple file with OriginalClientName, save into database with column called "document" but when data saved into database the file when uploading is not same the name,, i am upload file with name "cv bimo.docx", but in database, the name like this:
C:\Users\bimo_an\AppData\Local\Temp\phpAAF.tmp
i already using method getClientOriginalName(),,
this is my Function controller code :
..............................
$uploadFile = $request->file('document');
foreach($uploadFile as $file){
$filename = $file->getClientOriginalName();
$folder[] = $file->storeAs('uploads', $filename);
}
$data = [
'mto_number'=>$request->txtDocNumber,
'item_code'=>$request->txtItemCode[$key],
'required_qty'=>$request->txtRequiredQty[$key],
'spare_qty'=>$request->txtSpareQty[$key],
// 'file' => $path[$key]
'category' => $request->category[$key],
'document' => $file
];
ModelMTOItem::insert($data);
You are passing file Path instead of clientOriginalName
$uploadFile = $request->file('document');
foreach($uploadFile as $file) {
$filename = $file->getClientOriginalName();
$data = [
'mto_number'=>$request->txtDocNumber,
'item_code'=>$request->txtItemCode[$key],
'required_qty'=>$request->txtRequiredQty[$key],
'spare_qty'=>$request->txtSpareQty[$key],
// 'file' => $path[$key]
'category' => $request->category[$key],
'document' => $filename
];
ModelMTOItem::insert($data);
$folder[] = $file->storeAs('uploads', $filename);
}

logging all queries after execution in codeigniter

i want to log all queries after execution using hooks.
-i enabled hooks in config.php
-this is my hook-->
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
-and this is hook defination-->
class Db_log
{
function __construct()
{
}
function logQueries()
{
$CI = & get_instance();
$filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php';
$handle = fopen($filepath, "a+");
$times = $CI->db->query_times;
foreach ($CI->db->queries as $key => $query)
{
$sql = $query . " \n Execution Time:" . $times[$key];
fwrite($handle, $sql . "\n\n");
}
fclose($handle);
}
}
--its creating query_log file
--but no records of queries being stored
Your Code looks fine - the only reason why this doesn't work is in your DB Configuration - take a look #your DB Connection in the database.php under application/config/
There is an option "save_queries" which should be set to true
$db['default'] = array(
...
'save_queries' => TRUE
);
For me it only worked when I define de $hook array in config/hooks.php .

Uploading an image with Code Igniter?

I'm trying to set a site up so I can upload images using a web form in Code Igniter(CI). I'm not getting any errors but the file is not being saved either. I wanted to know if those that were successful in uploading images could help explain what might be the issue?
View:
<?php
echo form_open_multipart('admin/galleryUpload') . "\n";
echo "<div class='span-8'><span class='text'>Image:</span>" . form_upload('uploadImg') . "</div>";
foreach ($gallery as $picture)
{
$order[] = $picture->order;
}
$order[] = count($order) + 1;
echo "<div class='span-6 last'><span>Image Order #:</span>" . form_dropdown('order', $order) . "</div><div class='span-14'> </div>";
$conf = array('name' => 'alt_text', 'size' => '75');
echo "<div class='span-14 last'><span>Discription:</span>" . form_input($conf) . "<br /></div>";
echo form_hidden('propertyID', "$propertyID");
echo form_submit('upload', 'Upload');
echo form_close();
?>
Controller:
class Admin extends Controller
{
function galleryUpload()
{
if (! $this->session->userdata('is_admin'))
{
redirect('admin/index');
}
else
{
$this->load->model('admin_model');
$this->admin_model->imgUpload();
}
}
}
Model:
class Admin_model extends Model
{
function imgUpload()
{
$id = $this->input->post('propertyID');
$order = $this->input->post('order');
$alt_text = $this->input->post('alt_text');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png',
//'upload_path' => '../' . $this->imgPath($id),
'upload_path' => '../img/galleries/temp/',
'max_size' => '5000', // 5MB files max
);
$this->load->library('upload', $config);
$this->upload->do_upload();
$image_data = $this->upload->data();
$config = array(
'source_image' => $image_data['full_path'],
'new_image' => $this->imgPath($id) . '/thumbs',
'maintain_ratio' => TRUE,
'width' => '60'
);
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
}
From the user guide:
By default the upload routine expects the file to come from a form
field called userfile, and the form must be a multipart type
So you either have to change the name of the form field to userfile:
form_upload('userfile')
or pass the name of your form field to do_upload:
$this->upload->do_upload('uploadImg');

Resources