Upload profile video, instead of profile photo [closed]

I am trying to upload a MP4 file instead of a image file jpg,gif.

I tried changing the function in the thumb nail creation from image extensions to video MP4 extensions, which never work, as the thumb nail GD function don’t support video files.

I modified the gd function to get the upload MP4 file to the folder where the profile updates is stored, with it original file name, Instead of the unique id name meant to bind to the actual file,

It also never update the database

I think it something to do with the GD support function, but how could I do it without this function, and bind file instead of binding the thumbnail.

Profile photo

I am basically trying to use MP4 instead!! Please check the above

how to preg_match_all html tag in php [duplicate]

I am trying to get the data in the html code.

I tried to do something but it didn’t work. Can you help me?

$metin = "<div><b>bla bla bla</b>/<div>";
$pattern = '<div><b>(.*?)</b></div>';
preg_match_all($pattern,$metin,$haslar);
print_r($haslar);

How to disable the feature that shows the image source info in lower left corner of screen on pc and when I click on image it shows the name of image

So on my E commerce website when I hover on the image of any product I see a line in the lower left corner of the screen giving full information about the source of the image such as website name/wp-uploads/year/month/title of the image that I used when I saved it on my pc. Also when I click on the image I see the image title again just below the image. I don’t want my customers to see that information, please tell me how can I disable it.

I have tried asking chatgpt and Gemini to get a solution it told me to add some custom CSS codes but it didn’t work.

MySql and PHP for Ecommerce Project [closed]

I am developing an ecommerce website using Php and Mysql with help of google and youtube. I am new to PHP. Kindly guide me what are necessary knowledge i should gain and practice to get the website developed. There are many articles but got confused. Kindly guide me in details and required knowledge.

Error connect office365 with Webklex Laravel 11

I am trying to connect to Office 365 to retrieve emails.
I am using the Webklex library version 4.1.
I am able to obtain the authentication token to log into the email, but I always receive ‘connection setup failed’.

This is how I capture the authentication token.

private function getToken0Auth()
{
    try {
        $client = new GuzzleHttpClient();
        // Solicitar o token do endpoint de OAuth2 do Microsoft
        // laravel office
        $response = $client->post('https://login.microsoftonline.com/'.env('tenant_id').'/oauth2/v2.0/token', [
            'form_params' => [
                'client_id' => env('client_id'),
                'client_secret' => env('client_secret'),
                'scope' => 'https://outlook.office365.com/.default',
                'grant_type' => 'client_credentials',
            ],
        ]);
        $body = json_decode($response->getBody());
        if (!$body->access_token) {
            return ['success' => false, 'message' => 'Não foi possivel gerar o token.'];
        }
        return ['success' => true, 'token' => $body->access_token];
    } catch (Throwable $t) {
        return ['success' => false, 'message' => $t->getMessage()];
    }
}

This is an example of the token response:
eyJ0eXAiOiJKV1QiLCJub25jZSI6InNjUWJVeERrY3BvcjNsdVdaa080OERISDNsSDQwSmhEVk5QeXlVanBBb1EiLCJhbGciOiJSUzI1NiIsIng1dCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyIsImtpZCI6Ikg5bmo1QU9Tc3dNcGhnMVNGeDdqYVYtbEI5dyJ9.eyJhdWQiOiJodHRwczovL291dGxvb2sub2ZmaWNlMzY1LmNvbSIsImlzcyI6Imh0dHBzOi8vc3RzLndpbmRvd3MubmV0L2IzNDdhMGY0LTA3MzQtNDI5Ni05NzU3LTc2NzJkOGFjYjJhNC8iLCJpYXQiOjE3MjU2NDU5ODYsIm5iZiI6MTcyNTY0NTk4NiwiZXhwIjoxNzI1NjQ5ODg2LCJhaW8iOiJFMmRnWUxnbllYVWhjbzlWUU02SGEvM0poNXMvQWdBPSIsImFwcF9kaXNwbGF5bmFtZSI6IkxhcmF2ZWwgT2ZmaWNlIDM2NSBJbnRlZ3JhdGlvbiIsImFwcGlkIjoiMzkwNjJiNjMtZGY4OC00M2ZmLWI3MTktYWQ5M2Q3MjNlNDgxIiwiYXBwaWRhY3IiOiIxIiwiaWRwIjoiaHR0cHM6Ly9zdHMud2luZG93cy5uZXQvYjM0N2EwZjQtMDczNC00Mjk2LTk3NTctNzY3MmQ4YWNiMmE0LyIsImlkdHlwIjoiYXBwIiwib2lkIjoiZmFlZWFjYmEtZjcwZS00MmRjLThhZWYtYjdmNzFmNzBlM2ZiIiwicmgiOiIwLkFWZ0E5S0JIc3pRSGxrS1hWM1p5Mkt5eXBBSUFBQUFBQVBFUHpnQUFBQUFBQUFEeUFBQS4iLCJyb2xlcyI6WyJJTUFQLkFjY2Vzc0FzQXBwIiwiU01UUC5TZW5kQXNBcHAiXSwic2lkIjoiOWU3YjgxODctZmY5ZC00OWRiLTg1N2EtMWJiMDEyZGY4NjgwIiwic3ViIjoiZmFlZWFjYmEtZjcwZS00MmRjLThhZWYtYjdmNzFmNzBlM2ZiIiwidGlkIjoiYjM0N2EwZjQtMDczNC00Mjk2LTk3NTctNzY3MmQ4YWNiMmE0IiwidXRpIjoidWF5bHNEVkZ0VS1TN3luYUpVOEtBQSIsInZlciI6IjEuMCIsIndpZHMiOlsiMDk5N2ExZDAtMGQxZC00YWNiLWI0MDgtZDVjYTczMTIxZTkwIl0sInhtc19pZHJlbCI6IjcgMjgifQ.iZYBRa448-6E0oGNJU4FcXoeiDuhLTgDBQSMmJ-kyY1cOtsf3YHtl3b2HCYcRnanxLSa1v8WHxV2VR0KUH_FRUnDhAIVmHxztt039YvB3mk1znVXB7er6wDK_w07xRxH6ftvqo3ia8KPzXQXYGJ4iz2E8NyJYFlp8J_aj76fK2OncxHnTYe5HxyEkqWN50IKCTDoSFL_bEhmNLRhhAXm6O5od81KVC0sGz8BbhBD-QTLnoZRptb3SG1KTc0H-_uRvO8qAWYpwu3XCzNCETmiIuVVSyDUjafh6CinW8sAVm9kuBCtPpetzoYbljQlLjVyfE5Ppha8DmdFj2xtTYS4XA

After capturing the token, I use this function to connect to the IMAP server:

$oClient = Client::make([
    'host'          => 'outlook.office365.com',
    'port'          => 993,
    'encryption'    => 'ssl',
    'validate_cert' => false,
    'username'      => 'my-email',
    'password'      => $response['token'], // Token OAuth2
    'protocol'      => 'imap',
    'authentication' => 'oauth', // Definindo para autenticação OAuth
]);
$oClient->connect();

However, it always falls into the catch block, returning the same error: “connection setup failed”

In my Office 365 account, I had to register an app and grant permissions for access via IMAP.AccessAsApp
enter image description here

I also enabled IMAP for my mailbox.
enter image description here

Access to this application was created for any account.

I’m out of options at this point.

How to use PHP preg_replace on a formatted number based on search query while ignoring comma and decimal?

I want to highlight my search query on a formatted number.

For example:

$search_query = '1234'; // or $search_query = '7800';
$formatted_numeber = 12,345,678.00;

Currently my code is:

preg_replace('/(' . $search_query . ')/i', "<span style='background: yellow'>$1</span>", $formatted_numeber);

But this code fails to highlight search clause like ‘1234’ , ‘7800’ due to presence of commas (,) and decimal (.)

Also i want this to work with the presence of commas and decimals in the search query.

For example:

$search_query = '3,456';
$formatted_numeber = 12,345,678.00;

I want to highlight the part “345,6” on my formatted number.

Or:

$search_query = '7.80';
$formatted_numeber = 12,345,678.00;

I want to highlight the part “78.0” on my formatted number.

Passing properties to an Inertia Vue page for Laravel Fortify’s register view

I’m working on a web app that’s using Laravel 10, Vue 3, and Inertia. (I’m new to all of these, btw) Laravel is using Fortify for a lot of features, including new user registration. I’ve been tasked with changing the registration page to display some things from the database. As far as I can tell, the usual approach to this would be to add some properties on the Vue page, and then populate those properties via Inertia somewhere in the Laravel app (e.g. a controller).

The challenge I’m encountering right now is that Fortify currently sets up the “register” view (implemented in the Jetstream service provider; see https://github.com/laravel/jetstream/blob/4.x/src/JetstreamServiceProvider.php#L210), pointing to the Auth/Register Vue page, but provides no way to add properties to the Inertia rendering (as far as I can tell).

So the questions are:

  • Is there a way to add properties in the existing configuration of Laravel, Fortify, Inertia, and Vue?
  • Can I safely just call Fortify::registerView() from a new service provider I make? Or will this cause some sort of conflict issue with the existing implementation done by the framework?
  • Do I have to (or would it be better to) extend something to override this default behavior? (I know Laravel allows me to extend a binding… https://laravel.com/docs/10.x/container#extending-bindings)
  • Would it be better to approach this from a completely different angle? Such as leaving the page as-is on the backend, and then setting up the page in Vue to make a subsequent request to fetch the necessary data from the database?

Simple HTML DOM get a Tags value from inside div

Need get value from inside div sone tags with no div or class

<div class="pb-card rounded-3 nsofts_border" data-audio-id="58178" data-audio- 
name="Kirubai" data-audio-artist="talk,christian, gospel" data-audio- 
album="talk,christian, gospel" data-audio-url="http://s4.voscast.com:7110/;" data-audio- 
cover="https://d371i8ihhgym7w.cloudfront.net/13331.png">

How can i get that name inside “data-audio-name”.. But followinng code not work

foreach($html->find('div[class=pb-card rounded-3 nsofts_border]') as $a) {
    $name = $a->find('.data-audio-name', 0)->plaintext;

   print $a;

  echo $name; 
  echo "</br>";
}

How to post response to another URL after close iframe in php

Good day, i am trying to find solutions to post/reroute a response receive from a URL1 (ccRtnResponse1) to URL2 (ccTxnResponse2) after closing iframe in function URL1

<script>

    document.getElementById('mpiReqForm').submit();

    // Get iframe and loading circle elements
    const iframe = document.getElementById('transactionIframe');
    const loadingCircle = document.getElementById('loading-circle');

    // Hide loading circle and show iframe when the iframe has finished loading
    iframe.onload = function() {
        loadingCircle.style.display = 'none';
    };

    // Function to remove the iframe
    function removeIframe() {
        if (iframe) {
            iframe.remove(); // Remove the iframe element from the DOM
        }
    }

    // Listen for messages from the iframe
    window.addEventListener("message", function(event) {
        console.log('Message received:', event.data);
        // Check if the message is to close the iframe
        if (event.data === "closeIframe") {
            removeIframe(); // Call the function to remove the iframe
            // response receive from function ccRtnResponse1 will be pass to function ccTxnResponse2
        }
    });
</script>

so after receive the response

  public function ccRtnResponse1(Request $request)
{
  // This is in the iframe response, after processing
  echo '<script>window.parent.postMessage("closeIframe", "*");</script>';

  $data=$request->all;
  // repost the response $data to function ccTxnResponse2 after 'close iframe"

}

i would like to pass the $data to URL2(ccTxnResponse2)

  public function ccTxnResponse2(Request $request)
{
  dd($request->all());
}

i have tried to use appendChild but it seems not working. I hope to get some suggestion here. thank you

How to add CSS to text located in submit.php file

A contact form forms part of a single-page website. It is situated at the bottom of the page. When the form is completed successfully by a user a ‘success’ message is generated and displayed immediately above the contact form. I wish to add CSS to the text of that message. Specifically, centering the text and changing the colour.

The form is controlled by contact.php and submit.php. The actual text is contained in an ‘echo’ statement in submit.php.

contact form code

<div class="container">
     <div id="responseMessage"></div>
    <div class="wrapper">
        <div class="form-inner-cnt" id="contact-page">
            <!--  -->
            <!-- <form action="" method="post" class="cnt-form"> -->
             <form id="contactForm" method="post" class="cnt-form">
                
                <!-- Status message -->
                                
                <!-- Form fields -->
                <div class="form-input">
                    <input type="text" name="name" id="name" placeholder="Name" value="" required="">
                </div>
                <div class="form-input">
                    <input type="email" name="email" id="email" placeholder="Email" value="" required="">
                </div>
                <div class="form-input">
                    <textarea name="message" id="message" placeholder="Message" required=""></textarea>
                </div>
                </div>
                <input type="submit" name="submit" class="btn" value="SEND">
            </form>
        </div>
    </div>

Part of submit.php

        // Send email
                // @mail($toEmail, $emailSubject, $htmlContent, $headers);

                //   echo json_encode(['status' => 'success', 'message' => 'Thank you for your message. We will respond as soon as possible.']);


            if (mail($toEmail, $emailSubject, $htmlContent, $headers)) {

                echo json_encode(['status' => 'success', 'message' => 'THANK YOU FOR YOUR MESSAGE. WE WILL RESPOND AS SOON AS POSSIBLE.']);
            } else {
                echo json_encode(['status' => 'error', 'message' => 'Failed to send your message.']);
            }
} 
?>

Any assistance would be much appreciated

Why can’t I get my n:href attribute to work?

I’m still pretty new to the whole nette/latte framework and I’m currently trying to figure out pagination. I have tried to mostly follow the official documentation (which “somewhat” worked), but as soon as I try to implement the n:href attribute, I get the following error:

PHP message: PHP Fatal error:  Uncaught LatteCompileException: Unexpected attribute n:href 

This is where the error occurs:

    {if !$paginator->isFirst()}
        <a n:href="default, 1">First</a>
        &nbsp;|&nbsp;
        <a n:href="default, $paginator->page-1">Previous</a>
        &nbsp;|&nbsp;
    {/if}

    Page {$paginator->getPage()} of {$paginator->getPageCount()}

    {if !$paginator->isLast()}
        &nbsp;|&nbsp;
        <a n:href="default, $paginator->getPage() + 1">Next</a>
        &nbsp;|&nbsp;
        <a n:href="default, $paginator->getPageCount()">Last</a>
    {/if}

I really hope someone can help me here.

I have already tried to change the code from the documentation in a couple of different ways, but that didn’t work either 🙁

Like this for example:

    {if !$paginator->isFirst()}
        <a n:href="default, $paginator->getPage() = 1">First</a>
        &nbsp;|&nbsp;
        <a n:href="default, $paginator->getPage() - 1">Previous</a>
        &nbsp;|&nbsp;
    {/if}

I have also tried to leave out the n:href all together, but keeping it seems to be my best bet for solving the problem.

This main part of my php code:

$latte = new Engine;
$latte->setTempDirectory(__DIR__ . '/temp');
$latte->setAutoRefresh(true); 

$dsn = "mysql:host=" . DBHOST . ";dbname=" . DBNAME . ";charset=UTF8";
$database = new Connection($dsn, DBUSER, DBPASS);
$articles = [];
$articles = $database->fetchAll('SELECT * FROM production.requests WHERE archived = "1" ORDER BY order_date ASC;');
 
// Paginator setup
$paginator = new Paginator;
$paginator->setItemCount(count($articles));
$paginator->setItemsPerPage(2); // items per page
$paginator->setPage(1); // actual page number

$items = [];
$items = $database->fetchAll('SELECT * FROM production.requests WHERE archived = "1" ORDER BY order_date ASC LIMIT ? OFFSET ?', $paginator->getLength(), $paginator->getOffset());

$parameters = [
    'items' => $items,
    'paginator' => $paginator,
];

$latte->render(__DIR__ . '/templates/main/test.latte', $parameters);

Unable to get Laravel Spatie/Browsershot working with Puppeteer, Ubuntu 24.04, PHP 8.3, Chrom & Nginx

Environment:

  • PHP 8.3
  • Laravel 11
  • Ubuntu 24.04 LTS
  • NGINX
  • Node (v18.19.1) (latest for today)
  • Spatie/Browsershot (Puppeteer, Chrome 128.0.6613.119)

Issues:

  1. Spatie wanting me to install outdated Node/Puppeteer versions (https://spatie.be/docs/browsershot/v4/requirements). And we all want the latest.
  2. Even if we follow Spatie instructions, we get Permissions errors (www-data user cannot run Chrome or has no permissions to create temp directories).
  3. Other Chrome versions (chromium-browser or non-snap .deb installations) methods do not work (php8.3-fpm does not belong to Snap cgroup or other issues with permissions).
  4. Since we want to use the latest soft versions, some packages are missing.

PHP Ratchet websocket listening + sending

I need to establish communication in PHP with a websocket server that is hosted on a node. The first part is to establish a connection to listen for responses from the ws server. The second is to be able to send my own commands and track responses in the listener from the first part. I am using the symfony project and the ratchet/pawl package.

I have created such a client to establish a connection and send messages:

<?php

namespace AppWebSocket;

use RatchetClientWebSocket;
use RatchetClientConnector;
use ReactEventLoopLoop;
use PsrLogLoggerInterface;

class WebsocketClient
{
    private $connection;
    private $loop;
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->loop = Loop::get();
        $this->logger = $logger;
    }

    public function connect(string $url)
    {
        $connector = new Connector($this->loop);

        $connector($url)->then(function (WebSocket $conn) {
            $this->connection = $conn;
            dump('Connected to WebSocket');

            $conn->on('message', function ($msg) {
                dump("Received message: {$msg}");
                $this->onMessage($msg);
            });

            $conn->on('close', function ($code = null, $reason = null) {
                dump('Connection closed ({$code} - {$reason})');
            });
        }, function (Exception $e) {
            dump("Could not connect: {$e->getMessage()}");
        });
    }

    public function send(string $message)
    {
        if ($this->connection) {
            $this->connection->send($message);
        } else {
            echo "No connection established.n";
        }
    }

    private function onMessage($message)
    {
        $this->logger->info("Received message: {$message}");
    }

    public function run()
    {
        $this->loop->run();
    }

    public function close()
    {
        if ($this->connection) {
            $this->connection->close();
        }
    }
}

I also created a symfony command that sets up the ws server listening:

<?php

namespace AppCommand;

use AppWebSocketWebsocketClient;
use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentConsoleStyleSymfonyStyle;

class WebsocketListenCommand extends Command
{
    protected static $defaultName = 'app:listen-websocket';
    private $webSocketClient;

    public function __construct(WebsocketClient $webSocketClient)
    {
        parent::__construct();
        $this->webSocketClient = $webSocketClient;
    }

    protected function configure(): void
    {
        $this
            ->setDescription('Listens for and processes messages from WebSocket');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);

        $io->success('Listening for WebSocket messages...');

        $this->webSocketClient->connect('ws://x.x.x.x:y');

        $this->webSocketClient->run();

        return Command::SUCCESS;
    }

}

After running the above command, everything works fine. It receives responses in real time.

I would then like to send messages to the websocket server and track the response (while keeping the listening I set up earlier). It injects the service anywhere in the code and tries to send a message:

$this->webSocketClient->send('{"some json, doesnt matter"}');

When trying to use the send method, it doesn’t see any connection and can’t send the message. I have tried setting up the connection myself during send, but then my listener stops responding. Where does the problem lie? Perhaps ZeroMQ or some other solution needs to be used here? I would appreciate your help.

Validation error message do not match log error message in Laravel excel validation

How can I resolve an issue where my log error messages are correct, but the validation error messages displayed to the user show a different dose number than expected? Here’s my code for logging and validating doses for vaccines, but the row number in the validation errors doesn’t match the log output.


public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            $data = $validator->getData();

            foreach ($data as $key => $row) {
                $vaccine = $row['vaccine'];
                Log::info('$vaccine'.$vaccine);
                $inventory = Inventory::where('name', $vaccine)->where('inventory_type_id', 15)->first();

                if (!$inventory) {
                    Log::error("The vaccine '{$vaccine}' does not exist.");
                    $validator->errors()->add("vaccine", "The vaccine '{$vaccine}' does not exist.");
                } else if (isset($row['given_doses']) && (int)$row['given_doses'] > (int)$inventory->dose_numbers) {
                    $totalDoses=$inventory->dose_numbers;
                    $message="The DOSE set for '$inventory->name.' is  '$totalDoses' any dose given above '{$totalDoses}' should not be added.";
                    Log::info("Dose numbers for '{$inventory->name}': {$totalDoses}");
                    Log::info("Processing row {$key}: Vaccine ' {$vaccine}', Given Doses: '{$row['given_doses']}', Inventory Dose Numbers: '{$inventory->dose_numbers}'");

                    Log::error($message);
                    $validator->errors()->add($key, $message);
                }
            }
        });
    }

Here is the output of my log

[2024-09-05 13:59:08] local.INFO: Dose numbers for ‘FMD’: 25
[2024-09-05 13:59:08] local.INFO: Processing row 2: Vaccine ‘ FMD’, Given Doses: ’30’, Inventory Dose Numbers: ’25’
[2024-09-05 13:59:08] local.ERROR: The DOSE set for ‘.FMD.’ is ‘.25.’ any dose given above ’25’ should not be added.

and here is the message displayed in the view
There was an error on row 2. The DOSE set for ‘FMD.’ is ‘5’ any dose given above ‘5’ should not be added.

It should print the exact numbers of doses in both messages. Log is displaying corrext values and view is not.