Problem with generate multiple file mPDF codeigniter - codeigniter

Hello guys i'm a little bit confuse with my mpdf function in codeigniter to generate multiple file pdf, i tried to research and nothing can solve this is issue,
i have anchor that action to download function, and the idea is to call all function with mpdf generate in it. here is the code :
public function download($id)
{
$this->kehadiranDosen($id);
$this->nilaiSeminar($id);
$this->beritaAcara($id);
}
function beritaAcara($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Berita Acara
$html = $this->load->view('seminar/beritaAcara', $data, true);
$this->load->library('M_pdf');
$mpdf = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf->WriteHTML($html);
$mpdf->Output('BERITA ACARA,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf);
unset($html);
}
function kehadiranDosen($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Kehadiran Dosen
$html2 = $this->load->view('seminar/kehadiranDosen', $data, true);
$this->load->library('M_pdf');
$mpdf2 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf2->WriteHTML($html2);
$mpdf2->Output('KEHADIRAN DOSEN,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf2);
unset($html2);
}
function nilaiSeminar($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Nilai Seminar
$html3 = $this->load->view('seminar/nilaiSeminar', $data, true);
$this->load->library('M_pdf');
$mpdf3 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf3->WriteHTML($html3);
$mpdf3->Output('NILAI SEMINAR,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf3);
unset($html3);
}
and when i click it, only kehadiran dosen generated, anyone can solve this? thank you so much before

Related

Codeigniter 4 DOMPDF (2.0.0) PNG Image loading issue . PHP version 8.0.17

I am having an issue with DOMPDF image loading. I tried all the way to load the image but it won't work on my local / server.
isRemoteEnabled mode changed to true.
I wanted to load a PNG image.
Please help me if you have an idea of how to resolve this issue.
I really appreciate any help you can provide.
When i try this code am getting mem
Constructor:
$options = new Options();
$options->set('defaultFont', 'Helvetica');
$options->set('isRemoteEnabled', TRUE);
$options->set('debugKeepTemp', true);
$options->set('isHtml5ParserEnabled', true);
$this->dompdf = new Dompdf($options);
Fucntion :
$path = '../logo.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
#data
$data = array_merge($this->data, [
'title' => $this->title,
'word' => $this->word,
'breadcrumb' => array("0" => array("url" => base_url("home"), "title" => 'Home'), "1" => array("url" => $url,
"title" => $this->word_multi)),
'action' => $url,
'customerID' => $cid,
'siteID' => $site,
'contractRow' => $contractRow,
'base64' => $base64
]);
#Contract file name
$contract = str_replace('/', "-", $contractRow['contractNumber']);
#remove UTF8 issue header
$this->response->removeHeader('Content-Type');
#viewpage data
$this->dompdf->loadHtml(view($this->path_views . 'contract', $data));
$this->dompdf->set_option('defaultMediaType', 'all');
$this->dompdf->setPaper('A4','portrait');
$this->dompdf->render();
$this->dompdf->stream( $contract, array("Attachment" => false));
View
<td width="20%"> <img src="<?php echo $base64; ?>" /></td>

laravel livewire intervention images

I am trying to use Intervention image with Livewire to reduce the sizes and I am not succeeding. They can guide me or tell me if Livewire may not allow it.
I am trying to pass this methodology:
foreach ($this->imagenes as $pathGaleria) {
$imgUrl = $pathGaleria->store('imagenesPropiedades');
$img = imgPropiedades::create([
'url' => $imgUrl,
'property_id' => $this->propiedadId
]);
to this other way:
foreach ($this->imagenes as $pathGaleria) {
$imgUrl = $pathGaleria->store('imagenesPropiedades');
Image::make($pathGaleria)->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
})
->save($imgUrl);
$img = imgPropiedades::create([
'url' => $imgUrl,
'property_id' => $this->propiedadId
]);
}
but the page remains blank. Thank you.
I found this today, may work for you
https://gist.github.com/daugaard47/659984245d31b895d00ee5dcbdee44ec
+
$images = Collection::wrap($request->file('file'));
$images->each(function ($image) use ($id) {
$basename = Str::random();
$original = $basename . '.' . $image->getClientOriginalExtension();
$thumbnail = $basename . '_thumb.' . $image->getClientOriginalExtension();
ImageManager::make($image)
->fit(250, 250)
->save(public_path('/images/' . $thumbnail));
$image->move(public_path('/images/'), $original);
Model::create([
]);
});

Laravel Homestead Development: AJAX POST request gets redirected for unknown reason

I'm on Laravel 5.3 and I was working on a form I POST submit to the server. What I want to point out right at the beginning is that I have been working on this form for days, with no issues what so ever. Yesterday I was working in the store method of my controller, when all of a sudden the form won't submit at all anymore.
The opening form:
{!! Form::model($addon = new \App\Addon, ['name' => 'FinalForm', 'route' => 'addons.store', 'enctype' => 'multipart/form-data']) !!}
My route:
Route::resource('addons', 'AddonController');
php artisan route:list:
Method: POST
URI: addons
Name: addons.store
Action: App\Http\Controllers\AddonController#store
Middleware: web,auth
So what happens now is, the form gets posted, but then, for some reason, get's redirected. This is what chrome says:
POST request to /addons
And after that, for some reason, GET request to /addons/
As you can see I'm getting a 403 Forbidden response. Why is the request being redicted to /addons/ ??
As I said before, I changed NOTHING, I was working with the inner logic of the store method on the controller when this popped up. I even restarted the homestead box (and my whole machine), I don't know what is causing it.
EDIT (controller):
/**
* Store the addon.
*
* #return Response
**/
public function store(CreateAddonRequest $request, ImageHandler $imageHandler)
{
$input = $request->only('title', 'body', 'author', 'slogan', 'version', 'revision', 'published_at', '_img_data');
$session = $request->session()->all();
$slug = SlugService::createSlug(Addon::class, 'title', $input['title'], ['unique' => true]);
$imageHandler->move($slug, $input['body'], 'description');
$body = $imageHandler->body;
$addon = Auth::user()->addons()->create([
'body' => $body,
'title' => $input['title'],
'slogan' => $input['slogan'],
'author' => $input['author'],
'locales' => $session['locales'],
'published_at' => $input['published_at']
]);
$addon->categories()->attach($request->input('categories'));
Storage::makeDirectory('addons/' . $slug . '/files/');
$extension = Dir::extension('temp/' . $session['file_name']);
if ($input['revision'] != "") {
$file = $addon->slug . '-v' . $input['version'] . '-r' . $input['revision'] . '.' . $extension;
} else {
$file = $addon->slug . '-v' . $input['version'] . '.' . $extension;
}
Storage::disk('local')->move('temp/' . $session['file_name'], 'public/addons/' . $addon->slug . '/files/' . $file);
// With 5.4 we don't need that check anymore
if ($input['revision'] == "") {
$input['revision'] = null;
}
$addon->files()->create([
'file_name' => $file,
'hash' => $session['hash'],
'version' => $input['version'],
'revision' => $input['revision'],
'game_version' => $session['interface'],
'virustotal' => $session['virustotal']
]);
dd('done');
// if ($request->hasFile('images'))
// {
// Storage::makeDirectory('addons/' . $slug . '/images/');
// foreach ($request->file('images') as $image)
// {
// $imageName = uniqid() . '.' . $image->getClientOriginalExtension();
// //$image->storeAs('addons/' . $slug . '/images/', $imageName);
// $addon->images()->create(array('image_name' => $imageName));
// }
// }
// flash('The addon has been uploaded.');
// return redirect('addons');
dd('done');
return response()->json([
'success' => true,
'message' => 'Images checked',
]);
}

codeigniter update image not reuploading

I'm running over this problem which I was trying for the last few hours
I'm having an image upload with some details to store in db.
I store the details and image path, working like a charm. Now comes the edit part.
I'm trying to check if the input file is empty, if so update just the details, else delete the image and reupload new image. The problem is this:
If the input file is empty it updates everything no problem, if is not empty it is updating the details, but the image is the same, doesn't get deleted or reuploaded.
here is the code
$image_input = $this->input->post('image');
if(isset($image_input) && !empty($image_input))
{
$this->db->where('id', $id);
$img = $this->db->get('menus_category', 1);
if($img->num_rows() > 0)
{
$row = $img->row();
$original_image = $row->image;
$desktop_image = $row->desk_img;
$mobile_image = $row->mob_img;
$thumb_image = $row->thumb;
$unlink_image = unlink('./uploads/menus/' . $original_image);
$unlink_desk = unlink('./uploads/menus/desk/' . $desktop_image);
$unlink_mob = unlink('./uploads/menus/mobile/' . $mobile_image);
$unlink_thumb = unlink('./uploads/menus/thumbs/' . $thumb_image);
if($unlink_desk && $unlink_image && $unlink_mob && $unlink_thumb)
{
$config = array(
'upload_path' => './uploads/menus',
'allowed_types' => 'gif|jpg|jpeg|png',
'max_size' => '15000'
);
$this->upload->initialize($config);
if ($this->upload->do_upload('image'))
{
$image_data = $this->upload->data();
$this->load->library('image_lib');
// thumb resize
$thumbnail = 'thumb_' . $image_data['file_name'];
$thumb = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $image_data['file_path'] . 'thumbs/' . $thumbnail,
'maintain_ratio' => TRUE,
'width' => '90',
'height' => '90'
);
$this->image_lib->initialize($thumb);
$this->image_lib->resize();
$this->image_lib->clear();
// mobile resize
$mob = 'mob_' . $image_data['file_name'];
$thumb_mob = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $image_data['file_path'] . 'mobile/' . $mob,
'maintain_ratio' => FALSE,
'width' => '290',
'height' => '83'
);
$this->image_lib->initialize($thumb_mob);
$this->image_lib->resize();
$this->image_lib->clear();
// desktop resize
$desk = 'desk_' . $image_data['file_name'];
$thumb_desk = array(
'image_library' => 'GD2',
'source_image' => $image_data['full_path'],
'new_image' => $image_data['file_path'] . 'desk/' . $desk,
'maintain_ratio' => FALSE,
'width' => '700',
'height' => '200'
);
$this->image_lib->initialize($thumb_desk);
$this->image_lib->resize();
$this->image_lib->clear();
// insert path and details to database
$data = array(
'title' => $input['title'],
'slug' => $this->_check_slug($input['title']),
'description' => $input['description'],
'image' => $image_data['file_name'],
'desk_img' => $desk,
'mob_img' => $mob,
'thumb' => $thumbnail
);
$this->db->where('id', $id);
return $this->db->update('menus_category', $data);
}
else
{
echo $this->image_lib->display_errors();
}
}
}
}
else
{
$data2 = array(
'title' => $input['title'],
'slug' => $this->_check_slug($input['slug']),
'description' => $input['description']
);
$this->db->where('id', $id);
return $this->db->update('menus_category', $data2);
}
Note: the else statement works fine, but the first if the problem. Now I changed the if to just if(isset($image_input)) ... and if file input is not empty is reuploading the picture and updating the details fine, but if I update only the details with no picture, it is deleting the picture that is already uploaded and is not updating. (I think this is the problem but I can't figure out how to fix it).
If you will to give me some help or to put me on right direction I will be thankful.
Thanks guys
First, this would be a comment asking a question, but I don't have enough reputation do add one just yet...
If you could post your HTML form, that would be helpful, but without that...
1) I assume the form you are submitting has enctype="multipart/form-data" in the opening tag.
2) On line 2 of your code here, $this->input->post('image'), is 'image' from a form input of type file? If so, your statement won't work as 'image' is part of the $_FILES array and not $_POST anymore. Meaning when you go to check it, it is always going to be empty (or non-existent).
To verify that your form is submitting the way you think it is, do this just before the first line in the code you have in your post:
var_dump($_POST);
var_dump($_FILES);
exit; // don't let anything run after the dumps.
let me know if that puts you in the right direction or not.

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