简体   繁体   中英

A way to call a command prompt function from controller in Laravel?

I'm trying to make a thumbnail in a Laravel project and I tried a lot other ways but with no success - Libraries, APIs... The problem is that the project is developed in Windows and the professor needs it in Windows as well.

So far, I experimented to integrate different libraries (wkhtmltoimage, spatie/browsershot, mpdf and so) but in the most of the cases, there are problems with the path. The required function, which I need, works very good in command prompt and I thought that I must find a way to call it in the controller.

I've tried with:

shell_execute($call); 
system($call);
exec($call);

// with $call = "{func_name} {path_to_input_file} {name_of_output_file}";
// Example: $call = "wkhtmltoimage C:\xampp\htdocs\app\public\test.html img.jpg"

But no result. The function generates an image, which I want to store in the database.

Is there an other way to make a call to the command prompt? Maybe SSH call?

You can execute Artisan commands directly via your controller.

Look at this example from the Laravel documentation :

Route::get('/foo', function () {
    $exitCode = Artisan::call('email:send', [
        'user' => 1, '--queue' => 'default'
    ]);

    //
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM