Welcome Guest, Not a member yet? Register   Sign In
Using a third party library without composer
#1

(This post was last modified: 03-17-2025, 02:29 AM by occitan.)

I would like to use this library in a controller but without installing it with composer. How do i go about that?
https://github.com/MaestroError/php-heic-to-jpg
Where do I put the library and how do I properly namespace it?

Does this look correct?

require APPPATH . 'ThirdParty/HeicToJpg/src/HeicToJpg.php';
use Maestroerror\HeicToJpg;
Reply
#2

(This post was last modified: 03-17-2025, 10:46 PM by InsiteFX.)

1) Place the Library in app\ThirdParty

2) Open app\Config\Autoload.php

3) Add the Library to the $classmap

4) 'LibraryName' => APPPATH . 'ThirdParty/Libraryname.php',

5) Top of Controller - Use Libraryname

6) 
PHP Code:
$library = new myLibrary(); 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(This post was last modified: 03-17-2025, 03:09 AM by occitan.)

Okay awesome thank you!

I tried the above, do I need to include anything at the top of my Controller like the use keyword?
If I implement the class like this:


// autoload.php
PHP Code:
public $classmap = [
        'HeicToJpg' => APPPATH 'ThirdParty/HeicToJpg/src/HeicToJpg.php',
]; 

// Controller in a method
PHP Code:
$fileIsHeic HeicToJpg::isHeic($_FILES['image-input']['tmp_name']);

if (
$fileIsHeic) {
        Maestroerror\HeicToJpg::convert($_FILES['image-input']['tmp_name'])->saveAs($uploads_folder $filename '.jpg');


I get the error:
Error: Class "App\Controllers\HeicToJpg" not found
Reply
#4

Yes,

You need to add the class with the 'use' keyword.

Try adding:
PHP Code:
use LibraryName 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB