Submit post params with Files using CURL Call

I am trying to submit some post variables along with some files on 3rd party URL via CURL call.

For that i have used ajax from where i am passing whole form data on controller and from controller, i am calling CURL with form data.

but unfortunately those data is not passed to 3rd party URL.

here is controllers code
`

     $clientId = $this->request->data['clientSsoCert'];

     //file details which i wants to upload
     $xmlTmpPath = $this->request->data['clientSsoXml']['tmp_name'];
     $xmlType = $this->request->data['clientSsoXml']['type'];
     $xmlName = $this->request->data['clientSsoXml']['name'];
     $xmlNameCmps = explode(".", $xmlName);
     $xmlExtension = strtolower(end($xmlNameCmps));

CURL calls logic

$strRequestURL = 'https://abcd.com';
    try {
        $conn = curl_init($strRequestURL);

        curl_setopt($conn, CURLOPT_URL, $strRequestURL);
        curl_setopt($conn, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($conn, CURLOPT_POST, true);
        curl_setopt($conn, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
        curl_setopt($conn, CURLOPT_POSTFIELDS, ['custId' => $clientId , 'xmlfile' => $xmlTmpPath]);
        curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($conn, CURLOPT_SSL_VERIFYHOST, false);

        $output = curl_exec($conn);

        if (curl_errno($conn)) {
            return ['status' => false, 'error' => curl_error($conn)];
        } else {
            $response = json_decode($output);
            if ($response->status == 'error') {
                return ['status' => false, 'error' => $response->errorMessage];
            } else {
                return ['status' => true, 'xmlFileName' => ($response->xmlfileName) ?? "", 'certFileName' => ($response->certfileName) ?? ""];
            }
        }
        curl_close($conn);
    } catch (Exception $e) {
        return ['status' => false, 'error' => $e->getMessage()];
    }

Above codes returns error which i shows on SS.

I am not sure how to upload image using CURL so any suggestions for that ?
i have used

        curl_setopt($conn, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));

and also the same on html form.
while calling the same API via postman without passing any params the same error i got, from there i found my params are not reaching there, thats why that error is showing.
enter image description here

How to show the items that have the same id as the button when button is clicked?

I use filters that are taken from my database. When the filter is clicked it has to filter on the elements that have the same id as the buttons.

Right now I did the filter in the following way. But that’s not the way it should be.

How can I just show the items that have the same ID as the button when it’s clicked?

<div id="myDropdown2" class="dropdown-content">
          <input type="button" id='all' value='All'>
          <?php
          $query = 'SELECT * FROM `imslp_instruments` WHERE 1';
          $result = $conn->query($query);
          if ($result->num_rows > 0) {
              while ($row = $result->fetch_assoc()) {
                  $thisInstrument = $row['imslp_instruments'];
                  echo "<input type='button' id='btn' value='$thisInstrument'/>";
              }
          }
          ?>
</div>
const sheets = document.querySelectorAll('.shop-card');

let knop = document.querySelectorAll('#btn');

knop.forEach((btn) =>
  btn.addEventListener('click', (e) => {
    e.target.classList.toggle('active');
    liveSearch2(e.target.value);
  }),
);
function liveSearch2(button) {
  for (var i = 0; i < sheets.length; i++) {
    if (sheets[i].textContent.toLowerCase().includes(button.toLowerCase())) {
      sheets[i].classList.remove('is-hidden');
    } else {
      sheets[i].classList.add('is-hidden');
    }
  }
}

How to attach .sql file to my php application

I have a php application code and a *.sql file which was running in windows application.
I am trying to run this in my ubuntu pc. I installed xamp in ubuntu and successfully ran the php code. But the code is not running when I move to page which access the database.
How do I attach .sql file to my php code in ubuntu?
I am new to php and well as sql.

Platform api problem – returns all Exceptions as Json

After installing api platform there was a problem with deleting the cache, a message popped up:

Service "api_platform.error_listener": Parent definition "exception_listener" does not exist.

I fixed this error by adding:

api_platform.error_listener:
    class: apiPlatform.error_listener.
    arguments:
        $controller:"@api_platform.action.exception"
        $logger: "@logger"
        $debug: "%kernel.debug%"

to the services.yaml file

However, now all Exceptions are returned as json. How to set only exceptions for api to be json (/api), while all others I would like to restore Twig Exception.

how join laravel tables to get non intersected data

in my Laravel app I have 3 tables : users, documents and type_documents, the user have multiple documents and document have one type_document

| Documents       | 
| --------        |
| id              | 
| file            | 
| type_document_id| 
| user_id         | 

| type_documents | 
| --------       |
| id             | 
| name           | 

| users          | 
| --------       |
| id             | 
| name           | 
| type_document_d| 

I want select the types that are not used in documents table for the current user with eloquent
I try with this, but it give me the used type_documents :

$document_types = TypeDocument::leftJoin('docments' , function ($join) {
                    $join->on('type_documents.id', '=', 'douments.type_document_id')
                         ->where('documents.user_id', auth()->id());
                })
                ->applyFilters($request->all())
                ->latest()
                ->paginateData($limit);

I use Laravel version 8

what code I need change to help me remove remove index.php from my website url?

Below is my nginx.conf’s server code.
enter image description here

I have already try add below code,but it’s dosent’s work.

location / {
     if (!-e $request_filename){
          rewrite ^/(.*)$ /index.php/$1 last;
     }
}
location / {
    if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
        rewrite (.*) /index.php;
    }

}

how to create exit intent popup with custom content

I want to show a custom feedback popup when user tries to close my website tab/browser.

As I am using WordPress for my development. I don’t want to use plugin for it.

I am aware that this question has been asked a million times, but it seems this technology is not possible at the moment as it was in the past. Now that I research on this topic, all the exit intent popup only works when the user moves his pointer away from the document but not when the user closes the window or directs to another page.

In JavaScript, you could achieve the same using the onbeforeunload event but now it isn’t possible to override the default message that popups and use your own modal or alert message in place of it.

Is there any alternate way of it? If not in JavaScript, in another technology maybe? Or is it something that is no longer followed anymore?

I have tried using following code, even multiple codes

$(window).bind("beforeunload",function(event) {
    if(hasChanged) return "My message";
});

But it’s not working as expected.

Need help!

Read sentence ending with dot (.) without being interfered with a.m, p.m or middle names [duplicate]

I’m trying to read a sentence in between sentences that contains the word “gathering”.

[^rn.!]*(?i)gathering[^rn.!?]*[m.!?]+

Demo: https://regex101.com/r/eo8uTU/1

However, when the sentence also contains a middle name like R. or a.m or p.m, it fails to grab the entire sentence.

Hello there. Gathering for John R. Doe will be at 2 p.m. Don't miss out!

So, how can I grab the full sentence all the way to the final dot (.)?

how to get country, state, city name in database?? I want names to be displayed but instead id is displayed in database [closed]

cities table[countries table]states table](https://i.stack.imgur.com/ObyCi.png)


<?php

            $query = "SELECT * FROM `prac`";
            $query = "SELECT prac.id, countries.id, country, country_name FROM prac  JOIN countries ON prac.id = countries.id";
            
            
            // $query .= "SELECT * FROM prac JOIN countries ON prac.country = countries.country_name";
            // $query = "SELECT prac.id, countries.id FROM prac INNER JOIN countries ON prac.country = countries.id";
            // $query = "SELECT prac.id, countries.id FROM prac INNER JOIN countries ON prac.country = countries.id";
    
            $data = mysqli_query($con, $query);
        
                while($result=mysqli_fetch_assoc($data)){
                    
                ?>
    
               

instead of names ids are displayed in database

Retrive ACF group multiple fields

I created a group in ACF as follows:

1 – Relationship (casting_1)
2 – Function : (casting_role_1)
3 – Relationship (casting_2)
4 – Function : (casting_role_2)

Repeat these values ​​from 1 to 10
casting_1, casting_2, casting_role_1, casting_role_2 etc

I know I can return the values ​​as follows:

<?php if ( have_rows( 'casting_group' ) ) : ?>
  <?php while ( have_rows( 'casting_group' ) ) : the_row(); ?>
    <?php $casting_1 = get_sub_field( 'casting_1' ); ?>
    <?php if ( $casting_1 ) : ?>
      <a href="<?php echo get_permalink( $casting_1 ); ?>"><?php echo get_the_title( $casting_1 ); ?></a>
    <?php endif; ?>
    <?php the_sub_field( 'casting_role_1' ); ?>
    <?php $casting_2 = get_sub_field( 'casting_2' ); ?>
    <?php if ( $casting_2 ) : ?>
      <a href="<?php echo get_permalink( $casting_2 ); ?>"><?php echo get_the_title( $casting_2 ); ?></a>
    <?php endif; ?>
  <?php endwhile; ?>
<?php endif; ?>

this way the code will be huge because I will have to repeat it for + 50 values.

I need to customize values ​​so i use the while to manage it

if( have_rows('casting_group') ):
  while( have_rows('casting_group') ): the_row();
    if( $subfields = get_row() ) { ?>
      <?php
      foreach ($subfields as $key => $value) {
        if ( !empty($value) ) { $field = get_sub_field_object( $key ); ?>
          <?php
          $castImg = get_the_post_thumbnail_url($value, 'THUMB_150X150');
          $castLink   = get_permalink($value);
          $castTitle  = get_the_title($value);
        } ?>
        <a href="<?php echo $castLink ?>"><img src="<?php echo $castImg ; ?> "/><?php echo $castTitle ?></a>
      <?php }
    }
  endwhile;
endif;

the problem is that I can’t return the value of casting_role.

What I would like is to look like this:

— Casting 1: $value1 for casting_1// img, permalink etc.
— Casting Role 1: $value1 for casting_role_1 (text)

— Casting 2: $value2 for casting_role_2 // img, permalink etc.
— Casting Role 2: $value2 for casting_role_2 (text)

And so on.

Can you help me on this?

Get and loop values from acf fields group

How do I use a 3rd-party shortcode in Formidable Forms FILTERS in WordPress?

I’m building an IP address finder in WordPress with the help of Formidable Forms. I’ve created a functioning search page, but the IP range stored are all decimal intergets. The user input is always a dotted decimal (an IP address). So how do I convert the IP address to an integer when the user requests a search?

When the user searches, the website will take them to [siteurl]/search/?ip=[20 sanitize_url=1], [20 sanitize_url=1] is the IP address the user input.

The website then will display matching items under the filter start_of_ip_range <= ip (long) <= end_of_ip_range.

I’ve added a shortcode “ip2long” and “long2ip” with Shortcodes Blocks Creator Ultimate, and it works with pages, post, and even Formidable Forms Views, but seemingly not with Formidable filters.

However, when I tried to use [ip2long]ip[/ip2long], nothing shows up, which probably means that Formidable Forms doesn’t allow you to use 3rd-party shortcodes in filters.

One workaround I can think of is to use a medium url that converts the ip to a long integer, but I’m afraid it’ll be extremely slow.

Any idea how i can use the shortcode? Or do you have other ideas (even with another plugin so long as it can finish the request.)

How to use Postman environment variables inside PHP Curl?

enter image description here

This is from POSTMAN. I am confused about how to use these Postman environment variables in PHP Curl.

“BearToken” : “abc416abc416abc416abc416abc416abc416”

“HostURL” : “https://app.flowtrack.co”

“public_key” : “dj0lZewEkMlFZg0yMaQP”

“private_key” : “VOqAv6JcKV3sGRxT8Rm1fgkCWQ32Mg”

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => '/api/contact',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS =>'{
    "country": "US",
    "phone_country": "US",
    "first_name": "John",
    "last_name": "Test",
    "email": "[email protected]",
    "street": "Road 3",
    "city": "testing",
    "zip": "233334",
    "phone": "+17145757567",
    "dial_code": "1",
    "hasZip": true, 
    "hasState": true, 
    "company_id": "yep19k"
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

PHP: Curl-Request with XML-Response

I send a GET request with PHP curl and get an XML file as response.

$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $url);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/xml',
    'Accept-Encoding: gzip, deflate, br'
));
$result = curl_exec($curl_session );
curl_close($curl_session);

Unfortunately PHP returns me a string.

19520110PkwLimousineAudiRS3MetallicAllradantriebSchiebedachLeichtmetallfelgenZentralverriegelungElektr. FensterheberElektr. WegfahrsperreServolenkungABSESPNavigationssystemScheckheftgepflegtTempomatSitzheizungGarantieRegensensor

If I save the response directly in an XML file, then it works. However, I would like to work with the XML data without having to save it first. simplexml_load_string does not work, because the XML tag is missing in the string. How can I work directly with the XML data?

WooCommerce – Removing individual items from the cart, by selecting the package

Provided solution here Woocomerce Remove a specific cart items when adding to cart another specific items
If I understood correctly, this code helps in the case where I want to check whether one of the products 31 or 32 has been inserted and then remove product 37, and check whether one of the products 33 or 34 has been inserted and remove product 53. Did I understand correctly?

What happens if I have several bundle products, each of which contains X certain products, and I want to check if the bundle product has been placed in the cart, and if all the details it contains have been removed from it (because they are already included in it).

For example:
I have many products on the site –
Products A, B, C – in package #1
Products P, Q, X, Y, Z – in package #2
and products M, Y, Q, N – in package No. 3
The number of packages is not limited and the amount of products in each package is not fixed.

I want that as soon as you place a package, if the individual products included in it are removed from the basket so that there is no duplication in the basket.
If there is a way to pop up a message to the customer with a question like “The selected package already includes products A and B, do you want to remove them from the cart?” – That would be great.

The question is whether it is possible to improve the code in a convenient way to fit several sets of packages without having to copy-paste and change every time a new package is added.
But there should be a defined place in the code for adding the list of products, and a defined place for adding the list of packages, and the script would know how to run the test accordingly

I tried using the code that appears here: Woocomerce Remove a specific cart items when adding to cart another specific items

But it is limited to the number of packages and products

WordPress hide current blog post from related posts

I have my blog posts set up so that it shows a blog roll of other posts at the bottom. I am trying to hide the current post that the user is on from the other posts as it would not make sense to appear there.

The problem I am having is that it is hiding the first blog post from the blog landing page also. I am using the following code in my functions.php file:

add_action( 'pre_get_posts', function ( $query ) {
    // not an admin page and not the main query
    if ( ! is_admin() && ! $query->is_main_query() ) {
        $query->set( 'post__not_in', array( get_the_ID() ) );
    }
} );