how to resolve ” Expected SSH_FXP_STATUS” error?

According to below lines which has been used Media library (Laravel) ,image is created from multiple images , But I am getting ” Expected SSH_FXP_STATUS ” error after running in latest line.

    $canvas = imagecreatetruecolor(800 , 800);
                    $img1=imagescale( imagecreatefromjpeg($rand[ 0 ]), 400, 400 );
                    $img2=imagescale( imagecreatefromjpeg($rand[ 1 ]), 400, 400 );
                    $img3=imagescale( imagecreatefromjpeg($rand[ 2 ]), 400, 400 );
                    $img4=imagescale( imagecreatefromjpeg($rand[ 3 ]), 400, 400 );

                    imagecopy($canvas , $img1 , 0 , 0 , 0 , 0 , 400 , 400);
                    imagecopy($canvas , $img2 , 0 , 400 , 0 , 0 , 400 , 400);
                    imagecopy($canvas , $img3 , 400 , 400 , 0 , 0 , 400 , 400);
                    imagecopy($canvas , $img4 , 400 , 0 , 0 , 0 , 400 , 400);
                    imagejpeg($canvas , public_path('temporary/playlist/cover' . $name . '.' . 'jpg'));
                    $this->user_collection->addMedia(public_path('temporary/playlist/cover' . $name . '.' . 'jpg'))
                                          ->toMediaCollection('user-collection-image','storage');

What should I do to fix this kind of error?

JSON_PRETTY_PRINT works on localhost but doesnt work on server

On localhost xamp, it prints fine. But same script, when i uploaded it on server (cpanel hostgator php7) it stays without formatting.

Here is my code, data are same and fine. Chrome and not “View page source”. Php7.3 on hosting, php 8 on localhost, no errors

header('Content-Type: application/json; charset=utf-8');
echo(json_encode($data,JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) );

Heres screenshot on hosting and on localhost

enter image description here

Im getting CSS and JS not found laravel 9 app

I’m trying to add a custom UI to my Laravel 9 app. So I’m adding extra CSS and JS files to my app.blade.php But looks like its not loading properly.

enter image description here

As you can see http://127.0.0.1:8000/css/tailwind.output.css and http://127.0.0.1:8000/js/init-alpine.js files not loaded. But when i check default http://127.0.0.1:8000/css/app.css file. Its working. But both of these files resides in the same location, which is resources/css/ and resources/js/ folders. Why those custom css and js files not loaded.

enter image description here

<!DOCTYPE html>
<html :class="{ 'theme-dark': dark }" x-data="data()" lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="csrf-token" content="{{ csrf_token() }}">

        <!-- Fonts -->
        <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap">

        <!-- Styles -->
        <link rel="stylesheet" href="{{ mix('css/app.css') }}">

      <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
     
      <link rel="stylesheet" href="{{ asset('css/tailwind.output.css') }}">

      <script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js"defer></script>
     
     <script src="{{ asset('js/init-alpine.js') }}" defer></script>

        @livewireStyles

        <!-- Scripts -->
        <script src="{{ mix('js/app.js') }}" defer></script>
    </head>
    <body class="font-sans antialiased">
        <x-jet-banner />

        <div class="min-h-screen bg-gray-100">
            @livewire('navigation-menu')

            <!-- Page Heading -->
            @if (isset($header))
                <header class="bg-white shadow">
                    <div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
                        {{ $header }}
                    </div>
                </header>
            @endif

            <!-- Page Content -->
            <main>
                {{ $slot }}
            </main>
        </div>

        @stack('modals')

        @livewireScripts
    </body>
</html>

I’m using tailwind CSS, livewire, jetstream and Laravel 9

PHP – Echoing variable name returns correct value, but using variable in query as tablename throws error [closed]

I am stumped by a problem that has been bugging me for a few days now and cannot seem to find solution for it.

In my application’s back-end, I use a MySQL query in PHP to get table-name, stored in another table (bank_accounts), and then I store that value in a variable. Like so:

Database. Table name - bank_accounts

Table name – bank_accounts | Accessing table_name column from this

   $getbankledgername = "SELECT table_name FROM bank_accounts WHERE bank_name='Himalaya Bank' AND bank_acholder = 'New Hira Itta Udyog'";
  
  if($res = mysqli_query($con, $getbankledgername)) {

    $brow = mysqli_fetch_assoc($res);
    $bln = $brow['table_name'];
    echo($bln);

    $fetchBankBalance = "SELECT bl_balance from $bln ORDER BY bl_id DESC LIMIT 1";
  
    if($bankresult = mysqli_query($con, $fetchBankBalance)) {

      $bankrow = mysqli_fetch_assoc($bankresult);
      $bankbalance = $bankrow['bl_balance'];
      $newbankbalance = $amount + $bankbalance;
      $bankParticular = 'Cheque deposited of '.$custname;

      $bls = "INSERT INTO `{$jmd}` (`bl_id`, `bl_date`,`bl_part`, `bl_debit`,
      `bl_credit`,`bl_balance`) VALUES (null, '{$date}','{$bankParticular}','{$amount}','000000',
      '{$newbankbalance}')";

      if(mysqli_query($con,$bls)) {
          http_response_code(204);
          $transaction = [
            'bl_date'    => $date,
            'bl_part'    => $bankParticular,
            'bl_debit'   => $amount,
            'bl_credit'  => '000000',
            'bl_balance' => $newbankbalance,
            'bl_id'      => mysqli_insert_id($con)
            ];
            echo json_encode($transaction);
        }  
      

      else{return http_response_code(422);}

    }

  }

PHP Code

When I run this code in Postman, I get the following results –

bledger_himalaya_bank_nhiu
Fatal error: Uncaught
mysqli_sql_exception: Table ‘nhiu_accounting.bledger_himalaya_bank’
doesn’t exist in C:xampphtdocsbackendapichequesduetest.php:52
Stack trace:
#0 C:xampphtdocsbackendapichequesduetest.php(52): mysqli_query(Object(mysqli), ‘INSERT INTO `bl…’)
#1 {main} thrown in C:xampphtdocsbackendapichequesduetest.php on line
52

As you can see, the echo of the table name variable returns correct value, which is bledger_himalaya_bank_nhiu, but somehow the same variable when it is used in the query to insert data, returns error that table does not exist. But the table that Postman shows to be wrong is just a cut short version of the required table name (nhiu_accounting.bledger_himalaya_bank) minus the _nhiu part.

What is going on here? I am utterly confused. Any help will be much appreciated.

Cannot access to my PGSQL Docker container with PHP container

I’m setting up a CI using Docker using Github workflows for my Symfony project. I use for this an image of PHP8.1-fpm and Pgsql-13-alpine.

The docker-compose.test.yaml :

version: '3.3'
services:
    phptest:
        build: ./devops/docker/tests/docker/php
        volumes:
            - .:/var/www:delegated
        links:
            - dbtest
        networks:
            - test

    dbtest:
        image: postgres:${POSTGRES_VERSION:-13}-alpine
        environment:
            POSTGRES_DB: test
            POSTGRES_PASSWORD: test
            POSTGRES_USER: test
        ports:
            - 5431:5432
        networks:
            - test

networks:
    test:

The .env.test:

# define your env variables for the test env here
KERNEL_CLASS='AppKernel'
APP_SECRET='$ecretf0rt3st'
SYMFONY_DEPRECATIONS_HELPER=999999
PANTHER_APP_ENV=panther
DATABASE_URL=postgresql://test:test@dbtest:5431/test?serverVersion=13&charset=utf8

The PHP container works fine for the others tests and pdo_pgsql is installed inside my Dockerfile.

My Makefile looks like this :

DOCKER_COMPOSE = docker-compose
DOCKER_TEST = $(DOCKER_COMPOSE) -f docker-compose.test.yaml run --rm

.PHONY: test
test: ##@ Execute les tests
    $(DOCKER_TEST) phptest bin/console doctrine:schema:validate --skip-sync --env=test
    $(DOCKER_TEST) phptest bin/console doctrine:schema:update --force --env=test

When I tried to update the database schema I have this error :

An exception occurred in the driver: SQLSTATE[08006] [7] could not connect to server: Connection refused  
Is the server running on host "dbtest" (192.168.208.2) and accepting TCP/IP connections on port 5431?                                                                          

I tried to change the .env.test with 127.0.0.1 instead dbtest too but same error.

I tried a loot of fix by different topics I found without success. Someone has an idea ?

Thanks by advance

Loop table row dynamically (Class Shedule Maker)

I am trying to make a student class routine from mysql data using php. Where each table row (day name wise like Monday, Tuesday) I have to put day’s name manually,

I want to loop table row dynamic

<tr>  
    <td>Monday</td> 
<?php       
for ($x = 1; $x <= 8; $x++) {
    $ret=mysqli_query($con,"select * 
                            from routine 
                            WHERE period_name = $x 
                            and day = 'Monday' 
                            and class='ukg';");
    $cnt=1;
    $row=mysqli_num_rows($ret);
    if($row>0){
        while ($row=mysqli_fetch_array($ret)) {
?>
    <td><?php  echo $row['subject'];?> <br><?php  echo $row['teacher'];?><br><?php  echo $row['time_start'];?> - <?php  echo $row['time_end'];?></td> 
<?php 
            $cnt=$cnt+1;
        } 
    } else {
?>
<?php 
    }
} 
?> 
</tr>
<tr>                                               
    <td>Tuesday</td> 
<?php       
    
for ($x = 1; $x <= 8; $x++) {
    $ret=mysqli_query($con,"select *    
                            from routine 
                            WHERE period_name = $x 
                            and day = 'Tuesday' 
                            and class='ukg';");
    $cnt=1;
    $row=mysqli_num_rows($ret);
    if($row>0){
        while ($row=mysqli_fetch_array($ret)) {
?>
    <td><?php  echo $row['subject'];?> <br><?php  echo $row['teacher'];?><br><?php  echo $row['time_start'];?> - <?php  echo $row['time_end'];?></td> 
<?php 
        $cnt=$cnt+1;
        } 
    } else {
?>
<?php 
    }
} 
?> 
</tr>

Abstract class implementation in php

There is a code supporting calculation if a car is damaged.
Now it should be extended to support calculating if a painting of the car’s exterior is damaged (this means, if a painting of any of the car details is
not OK – for example a door is scratched).

abstract class CarDetail
{
    protected $isBroken;

    public function __construct(bool $isBroken)
    {
        $this->isBroken = $isBroken;
    }

    public function isBroken(): bool
    {
        return $this->isBroken;
    }
}

class Door extends CarDetail
{
}

class Tyre extends CarDetail
{
}

class Car
{
    /**
     * @var CarDetail[]
     */
    private $details;

    /**
     * @param CarDetail[] $details
     */
    public function __construct(array $details)
    {
        $this->details = $details;
    }
    
    public function isBroken(): bool
    {
        foreach ($this->details as $detail) {
            if ($detail->isBroken()) {
                return true;
            }
        }
        return false;
    }

    public function isPaintingDamaged(): bool
    {
    // MAKE AN IMPLEMENTATION
    }
}

i want to achieve like following by using abstract class. and i do not know how to achieve it.

$car = new Car([new Door(true), new Tyre(false)]); // we pass a

redirect open page not fancybox

i use fancybox to open payment gateway inside my site

everything working good
but when gateway return response to my endpoint that i must redirect my client to another page
the redirect done in fancybox iframe not in active tab page

my code
JQuery

Fancybox.show([ { src: response, width : '100%', height : '100%', touch : 'false', autoScale : 'false', autoDimensions : 'false', scrolling : 'false', transitionIn : 'none', transitionOut : 'none', type : 'iframe' , iframe : { scrolling : 'no' } } ]);

endpoint php code

$order_id = $parameters['merchant_order_id']; wp_safe_redirect( '/order-status/?error=' . $order_id); exit;

all ways but no solve

How to check the file type with Laravel Facades?

Is there a convenient way to check the file type of a file with the File facade? I can check the file extension like so:

$ext = File::extension('623d91b094472.png');

I know I can derive the file type from the file extension but it would require some conditional string manipulation, so was wondering if there is a more convenient way to just get it from a facade like File::type(...) or such.

I need the file type because I’m encoding files in Vue.js and decoding them in Laravel, which requires the replacement of the file type and file extension in the base64 string:

$file64 = str_replace('data:image/png;base64,', '', $request->file);

I’ve tried this:

$type = File::type('623d91b094472.png');

but it throws:

local.ERROR: filetype(): Lstat failed for 623d91b094472.png {"userId":16,"exception":"[object] (ErrorException(code: 0): filetype(): Lstat failed for 623d91b094472.png at /Users/artur/PhpstormProjects/safa-ameedee.com/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php:433)
[stacktrace]

foreach loop does not execute

I am trying to store values to array using foreach loop, here is my code

public function priceRegulation(){
        $prices = Price::where('hotel_id', $this->id);

        $lowerPrices = [];

        if($prices->count() > 0){
            foreach ($prices as $price) {
                
                    $lowerPrices[] = $price;
                
            }

            if(sizeof($lowerPrices) < 1){
                return false;
            } else{
                return true;
            }
        } else{
            return 'empty';
        }
    }

I have also tried setting $lowerPrices to 0 (int type) and increment it through foreach, but result was the same variable remaind at 0. I have tested if statements and they work fine. The problem is with foreach it basically does nothing. I am using Laravel Framework.
Any help is welcome!
Regards

cant access json array using php

how i can access
and callback_query->data
why i cant access $update->callback_query->data;
here is my code:
$update = file_get_contents('php://input'); $update = json_decode($update, true); $callbak= $update->callback_query->data;

here is the response:

{"ok":true,"result":[{"update_id":167251858,
"callback_query":{"id":"3952005903777779004","from":{"id":5215115374,"is_bot":false,"first_name":"Task","last_name":"Paut","username":"ma2231","language_code":"en"},"message":{"message_id":157,"from":{"id":5114398973,"is_bot":true,"first_name":"SYsBot","username":"taskin221"},"chat":{"id":5215115374,"first_name":"Task","last_name":"Payout","username":"ma2231","type":"private"},"date":1648165511,"text":"Please enter pin;","reply_markup":{"inline_keyboard":[[{"text":"1","callback_data":"1"},{"text":"2","callback_data":"2"},{"text":"3","callback_data":"3"}],[{"text":"4","callback_data":"4"},{"text":"5","callback_data":"5"},{"text":"6","callback_data":"6"}],[{"text":"7","callback_data":"7"},{"text":"8","callback_data":"8"},{"text":"9","callback_data":"9"}],[{"text":"<","callback_data":"<"},{"text":"0","callback_data":"0"},{"text":"OK","callback_data":"ok"}]]}},"chat_instance":"-5726646197225582946","data":"9"}}]}``

PHP7.4 not running on apache2

I’m running trying to run php7.4 on an Apache2. For some reason, when I try to run any use any php scripts in my code, they do not run, and all that is shown is the comment.

What I have in my code is this:

<?php                                                                                                                  
include("developers.php");                                                                                             
?> 

However, what shows up on the html source when loaded in a browser is this:

<!--?php
include("developers.php");
?--!>

I’ve tested this with multiple different scripts, so I do not believe that it is any issue with the php itself. I also installed php7.4, as well as libapache2-mod-php7.4. I also enabled the php7.4 module in apache2.
Furthermore I have tried multiple different .htaccess and apache2.conf configurations, including adding

<FilesMatch ".php$">
    SetHandler application/x-httpd-php
</FilesMatch>

and

<FilesMatch "/.php$">
    SetHandler application/x-httpd-php
</FilesMatch>

I noticed that when I did not include the <FilesMatch> tags, then the php code will run, however then the page itself breaks, and the javascript and css on my page does not run properly.

I am running my server on Debian 11, if that helps.

Can anyone help me with this?

Laravel category tree children missing custom relationships

i need to display category as tree view, i did it using relationship:

public function children()
{
    return $this->hasMany(self::class, 'parentid');
}

but i also need to displayicon for both parent and children:

public function iconData()
{
    return $this->hasOne(Attachment::class, 'id', 'iconId');
}

i eager load the relationship in controller:

public function index(ProductCategory $productCategory)
{
    return new ProductCategoryCollection(ProductCategory::with(['children', 'iconData'])->where('parentid', '=', 0)->get());
}

but i only get icon data for parent, so i changed the children relationship to

public function children()
{
    return $this->hasMany(self::class, 'parentid')->with(['iconData']);
}

now both parent and children have icon data. but i find that laravel fetch the attachment data with two queries, one for parent and the other for children:

bindings: [“865”, “867”]
connection: {}
connectionName: “mysql”
sql:
“select * from attachment where attachment.id in
(?, ?)”
time: 1.61

bindings: [“864”, “866”]
connection: {}
connectionName: “mysql”
sql: “select * from
attachment where attachment.id in (?, ?)”
time:
0.6

is there more elegant way to do this?