Base64 decoded image is corrupted when sending to S3 bucket

I have a base64 image and I will send it to amazon S3 but when it is uploaded the jpeg is 0kb in size and it is corrupted.
by the way I am using AWS SDK for PHP.

Here is my PHP code:


`<?php
include ‘multi-step/connection.php’;
require ‘../vendor/autoload.php’;

$image = $_POST['image'];
$studentID = date("Y"). '-' .mt_rand();

$image_parts = explode(";base64,", $image);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = $image_parts[1];

$decodedImage = base64_decode($image_base64);


$args = [
    'credentials' => [
        'key' => '<KEY>',
        'secret' => '<SECRET KEY>',
    ],
    'region' => 'ap-southeast-1',
    'version' => 'latest'
];

use AwsS3S3Client;

try{

$sdk = new AwsSdk($args); /*Instantiate SDK class with configs for API use*/

$s3Client = $sdk->createS3(); /*creates the S3 Client for API use*/

$key = 'i-attend-faces/' .$studentID. '/facereference.jpeg';

/*print_r($_FILES['file']);*/
$result = $s3Client->putObject([
    'Bucket' => 'iattendfacebucket',
    'Key' => $key,
    'Body' => $decodedImage,
    'ContentType'=> 'image/jpeg',
]);
echo "FILE SENT";
echo $result;
}catch(Exception $e){
echo $e;
}`

I tried decoding it and then place it in the Body but it is also corrupted.

How to send a reminder in teams as a scheduled message

i’m using teams and i need to set reminders in a channel. I have the application for reminders set in the channel. At the moment i’m using webhooks for sending messages from an external application in this channel, but if i send a message like @remind [“what”] [when], this message is not processed as a command and is viewed like a “text” message. I would ask, is there a method to send reminders in this way? I wouldn’t use MS graph and create an application on Azure. For the reminders i’m using the app published by 88 Ventures Limited. Thanks to all can support me

I’m developing in javascript/PHP and this is the code:

var text= "@remind &quot;Reminder: "+task.trim()+" - "+change.trim()+" from *"+time.substr(0,16)+"* to *"+end.substr(0,16)+"* - "+title+" ```"+descr.replace(/s+$/, '')+"``` at 10:56&quot;";

i’m able to send the message with an ajax request, but in teams i get the message not processed but in “plain text”.

Multiple records insert with one Query

I’m having an issue with figuring out my INSERT query.

What I want to do is the following:

I want to insert the availability of a user based on his giving information.

The user got a simple dashboard with:

Day ( ) Yes / ( ) No – Start time: XXXX End time: XXXX

For the day i use a radio button from monday till sunday with yes having its value=”” being the name of the day and the name=”” attribute named day.

No is empty which is set to default NULL,, and start end time use an input field with type=”time”

My Table is setup as followed:

Table name: Availability
Cols: available_id (AI), available_worker_id available _day,(text) available _start(text), available _end(text)

Now here come’s the part I cant figure out,

What if I select Monday Friday and Sunday only ? How would I create a query where the results would be as followed:

[1] [Monday] [1] [09:30] [12:50]
[2] [Friday] [1] [10:40] [17:30]
[3] [Sunday] [1] [07:00] [21:00]

Would I require to create the insert as followed:

INSERT INTO `availability` (`available _day`,` available_start`, `available _end`) VALUES (?), (?,?) 

Because with this query I’ll be ending up that the cols available_start, available_end getting there own values from my post and that the available_day get its own value’s. Atleast that is what I understand so far with my knowledge.

Uncaught ReferenceError: button_function is not defined at HTMLButtonElement.onclick

In the heading of page.php, I’m adding include('range.php'); withrange_function(); inside, which successfully returns an array. In page.php I’m using foreach loop to generate buttons from this array values:

 $arr = range_function();
 foreach ($arr as $item) {
    ?>
    <button onclick="button_function($item)"><?= $item ?> </button>
    <?PHP
 } 

to display the name of value with the button and pass it to another function:

function button_function($input) {
  /// ...
}

Then I get the error:

page.php?title=category1:124 Uncaught ReferenceError: button_function
is not defined
at HTMLButtonElement.onclick (page.php?title=category1:124:101) onclick @ page.php?title=category1:124

composer error on Magento while updating dependencies

I need help please, i’m getting stuck in setting up a magento open source system on docker

below are the lines I enter to create a new composer project using magento open source followed by the error i get…

composer create-project –repository-url=https://repo.magento.com/ magento/project-community-edition magento2-docker
Creating a “magento/project-community-edition” project at “./magento2-docker”
Installing magento/project-community-edition (2.4.5-p1)

  • Installing magento/project-community-edition (2.4.5-p1): Extracting archive
    Created project in C:UsersNoorDocumentsmagentomagento2-docker
    Loading composer repositories with package information
    Updating dependencies
    Your requirements could not be resolved to an installable set of packages.

Problem 1
– Root composer.json requires magento/product-community-edition 2.4.5-p1 -> satisfiable by magento/product-community-edition[2.4.5-p1].
– magento/product-community-edition 2.4.5-p1 requires ext-intl * -> it is missing from your system. Install or enable PHP’s intl extension.
Problem 2
– magento/magento2-functional-testing-framework[3.7.0, …, 3.11.0] require ext-intl * -> it is missing from your system. Install or enable PHP’s intl extension.
– Root composer.json requires magento/magento2-functional-testing-framework ^3.7 -> satisfiable by magento/magento2-functional-testing-framework[3.7.0, …, 3.11.0].

To enable extensions, verify that they are enabled in your .ini files:
– C:phpphp.ini
You can also run php --ini in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with --ignore-platform-req=ext-intl to temporarily ignore these required extensions.

Getting 500 POST Error when trying to send an email

I’ve been getting this error and I don’t know what’s wrong.
This is my .js code:

function save(formulario, tipo, file) {
    var formData = new FormData();
    formData.append("formulario", formulario);
    formData.append("tipo", tipo);
    formData.append("file", file);
    $.ajax({
        data: formData,
        url: 'php/save_form.php',
        type: 'POST',
        crossDomain: true,
        jsonpCallback: 'jpCallback',
        processData: false,//
        contentType: false,//
        dataType: "json",
        success: function (data) {
            if (data == "-1") {
                $(".modal-body>h5").html("ERROR");
            } 
            $(".modal").modal('show');
        },
    });
   
}

And then this is my .php file:

<?php
require 'vendor/autoload.php';
use MailjetResources;

$json = $_REQUEST['formulario'];

$json = json_decode($json);
$Email = $json->mail;
$json =  sendMail($json);

Here is the sendMail function.

function sendMail($json)
{
    
    $mj = new MailjetClient('12163db52d218cd7ea59430b24694a76','8e625a6b7d95d3b37f65b29c82102a4d',true,['version' => 'v3.1']);
    $body = [
        'Messages' => [
            [
            'From' => [
                'Email' => "[email protected]",
                'Name' => "Mailjet Pilot"
            ],
            'To' => [
                [
                    'Email' => "[email protected]",
                    'Name' => "passenger 1"
                ]
            ],
            'Subject' => "Your email flight plan!",
            'TextPart' => "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!",
            'HTMLPart' => "<h3>Dear passenger 1, welcome to <a href="https://www.mailjet.com/">Mailjet</a>!</h3><br />May the delivery force be with you!"
        ]
    ]
    ];

    
    $response = $mj->post(Resources::$Email, ['body' => $body]);
    $response->success() && var_dump($response->getData());
 
    return $response;
}

The error shows when I add the last two lines. If I don’t add them the error won’t appear but it won’t send the email.

Mail function working properly on localhost but on godaddy server sending email on junk

I am have having Go daddy shared hosting, in which we are running laravel php system.
Now when we are sending email using Mail::send it is ending up in junk.

here is my ENV file details

MAIL_DRIVER=sendmail
MAIL_HOST=smtp.rediffmailpro.com  
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
[email protected]
MAIL_FROM_NAME="[email protected]"
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="Test Name"

Are we using proper setting, or Godaddy should use different setting

Extracting information from a static array Symfony 6

help me please!

I have a table in a database

Cars
====
1
2
3
4
4
2
3
1
4
2
===

I have a static array

cars = 
[
1 => 'BMW',
2 => 'Honda',
3 => 'Toyota',
4 => 'Mazda',
]

How can I change data from a table to data from a static array when displaying data?

I tried

private $car;
protected const cars = [
    1 => 'BMW',
    2 => 'Honda',
    3 => 'Toyota',
    4 => 'Mazda',
];

public static function getCars() {
    return self::cars;
}

public static function getCarCaption($car) {
    return self::cars[$car];
}

Laravel livewire wire:model is not working?

The data is being sent from the livewire component to the livewire blade file but when I try to apply the wire:model then it isn’t sending the ajax request from the livewire blade to the livewire component.

index.blade.php

<div class="card-header p-4 min-h-unset" id="kt_contacts_list_header">
    <!--begin::Form-->
    <p> Name: {{$name}}</p> <!--it is printing the name coming from the livewire component-->
    <form class="d-flex align-items-center position-relative w-100 m-0" autocomplete="off">
        <!--begin::Icon-->
        <!--begin::Svg Icon | path: icons/duotune/general/gen021.svg-->
        <span class="svg-icon svg-icon-3 svg-icon-gray-500 position-absolute top-50 ms-5 translate-middle-y">
                    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">
                        <rect opacity="0.5" x="17.0365" y="15.1223" width="8.15546" height="2" rx="1" transform="rotate(45 17.0365 15.1223)" fill="black" />
                        <path d="M11 19C6.55556 19 3 15.4444 3 11C3 6.55556 6.55556 3 11 3C15.4444 3 19 6.55556 19 11C19 15.4444 15.4444 19 11 19ZM11 5C7.53333 5 5 7.53333 5 11C5 14.4667 7.53333 17 11 17C14.4667 17 17 14.4667 17 11C17 7.53333 14.4667 5 11 5Z" fill="black" />
                    </svg>
                </span>
        <!--end::Svg Icon-->
        <!--end::Icon-->
        <!--begin::Input-->
        <!--Livewire model-->
        <input wire:model="name" type="text" class="form-control form-control-solid ps-13" name="search" value="" placeholder="{{__('Search contacts')}}" />
        <!--end::Input-->
    </form>
    <!--end::Form-->
</div>

index.php

<?php

namespace AppHttpLivewireTenantModulesContacts;

use LivewireComponent;

class Index extends Component
{
    public $group;
    public $name;

    public function mount()
    {
        $this->name = 'Zain';
    }
    
    public function render()
    {
        return view('livewire.tenant.modules.contacts.index');
    }
}

enter image description here

enter image description here

How to eliminate render blocking JavaScript files without async or defer? [closed]

I’m trying to rectify performance issues of website https://www.writtenlyhub.com/ but I’m not being able to completely eliminate render-blocking resource.

Deferring the file or async is not working. The js files are never getting executed when async or defer is used.

Note:I have the same header file for all the pages and the location of these files are dynamically loaded using php.

Can someone please help me out here?

Thanks

Upload a file inside a JS FormData object through PHP using fetch

I’m sending a FomData object using fetch, that contains all my form elements, including a PDF file to upload. I am successfully receiving the data in my PHP file but, How can I upload the file from the FormData object?

my JS file:

//extracts all data from my Form
const formD = new FormData($(this)[0]);
var object = {};
formD.forEach((value, key) => object[key] = value);

//sends data to the php file
fetch('/modules/editData.data.php', {
method: "POST",
headers: {
"Content-Type": "application/json; charset=UTF-8"
},
body: JSON.stringify(object)
})
.then(res => res.json())
.then(data => console.log(data));
}  
});

my PHP file:

$json = file_get_contents('php://input');
$data = json_decode($json);

$fileID  = $data->fileID;
$name    = $data->name;
$file    = ???? 

I have tried

if(isset($_FILES['files'])) {
    echo json_encode('OK');
}

but no results where obtain. The rest of the data from the form is fine, I just need to know how to obtain the file from the FormData to use PHP move_uploaded_file

How can I check for a conflict between the dates and times in PHP/SQL?

I’m working on a project where parents are able to make reservations for a scheduled babysitter, and I’m having trouble finding a way to ensure that the babysitters aren’t able to accept two job reservations which would result in a time conflict. The way i’m doing it is to try and make it so that the only job requests being pulled from the database are the ones that wouldn’t cause any issues.
For my job reservations requests table, I have the following columns: Starting date, ending date, starting time, and ending time.

For example, if the babysitter is already scheduled for babysitting from November 6th to November 10th, from 10 AM to 5 PM, he/she wouldn’t be able to accept reservations for November 7th to November 15th from 12 PM to 7 PM, as there would be a time conflict in the first few days. However, he/she will be able to accept reservations from, for example, November 7th to 15th from 6 PM to 10 PM as there are no time conflicts (his/her first reservations ends before the next one starts).

So the conditions where there are no conflicts are:

  • The new reservation’s ending date is before the pre-existing reservation’s starting date
  • The new reservation’s starting date is after the pre-existing reservation’s ending date
    OR (in the case where both reservations have overlapping dates)
  • The new reservation’s ending time is before the pre-existing reservation’s starting time
  • The new reservation’s starting time is after the pre-existing reservations’ ending time

Some vars in my query:

$startDate //the starting date of the new job request, as a date type in my database
$endDate //the ending date of the new job request, as a date type in my database
$startTime //the starting time of the new job request, as a time type in my database
$endTime //the ending time of the new job request, as a time type in my database

The query i’ve tried to check for a date/time conflict is:

SELECT * FROM jobRequests WHERE babysitterID = ".$_SESSION['babysitterID']." 
AND ( ( $endDate >= startDate OR $startDate <= endDate OR ($startDate> startDate AND $endDate < endDate) ) 
AND ($startTime <= endTime OR $endTime >= startTime) )";

Which gives me an error when trying to check the number of rows of the query result.

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given
I hope my question is clear enough..

HTML and While loop in PHP

I have two questions if anyone can help me.

1- Is it okay to echo HTML elements in PHP or is it not preferred? I am asking this cz I read and heard that many people say it is bad practice to do so.

2- How can you break out of php while using a while loop and output all the elements? My code below only outputs the most recent element inserted in the database. However, if I echo all the HTML elements inside the php tags it works perfectly and I can output everything in the database. I have searched online but I could not find what I am looking for.

I have searched online and could not find what I was looking for so any help is appreciated.

        <?php 

            $edu_details_query = "SELECT school_title, school_content FROM cv_education ";

            $edu_stmt = mysqli_stmt_init($conn);

            if (!$edu_stmt_prepare = mysqli_stmt_prepare($edu_stmt, $edu_details_query)) {
                
                echo "QUERY FAILED" . mysqli_error($conn);

            } else {

                mysqli_stmt_execute($edu_stmt);

                $edu_details_result =  mysqli_stmt_get_result($edu_stmt);

                while ($edu_details_rows = mysqli_fetch_assoc($edu_details_result)) {

                $edu_details_row_school_title = $edu_details_rows['school_title'];
                $edu_details_row_school_content = $edu_details_rows['school_content'];


                     } ?>

                    <div id='masters-edu'>

                        <h2><?php echo $edu_details_row_school_title; ?></h2>

                        <div id='edu-details'>
                            
                         <?php echo $edu_details_row_school_content; ?> 
                            
                         </div>


                    </div>


                <?php } ?>

NOTE: Please do not mind how I am querying the database, this is just for practice purposes. Do let me know if you have input though (my main reason for using prepared statements is because it has better security than mysqli)