Is it possible to use both XSendFile and mod_rewrite (with relative paths)?

I’m getting a puzzling error when using XSendFile and mod_rewrite.

XSendFile works properly when serving a file from a PHP script without a rewritten URL, but breaks causing a 404 error when a URL rewrite is happening.

To recreate the issue I’ve made a test directory with a .htaccess, a php script, and a video file.

The .htaccess:

RewriteEngine On
XSendFile On

RewriteRule ^file.mp4$ file.php [QSA,L]

The PHP script (file.php):

<?php

$video = 'target_file.mp4';
header('X-Sendfile: ' . $video);
exit();

?>

These are in a directory /var/www/xsendfile_test/

When I load http://localhost/xsendfile_test/file.php, it works as expected and I get the video file.

When I load http://localhost/xsendfile_test/file.mp4, I get a 404 error.

(If I remove XSendFile and just send the video via PHP using readfile() it works with the redirect, so I know the .htaccess is working).

Here’s the weird part: my assumption was that the redirect shouldn’t affect XSendFile, because the redirect happens on the request to the server, and XSendFile only gets involved when the server is about to send headers back to the client.

But, looking at the Apache error log, I see this: [:error] [pid 10961] (2)No such file or directory: [client 127.0.0.1:58236] xsendfile: cannot open file: redirect:/xsendfile_test/target_file.mp4

Looks like XSendFile is noticing that there’s a redirect going on, and failing to find the file.

In order to get an exact comparison between what XSendFile is doing with redirected vs non-redirected URLs, I changed the target file in the PHP script to a non-existent filename. This means I get an Apache error with both rewritten and non-rewritten URLs, to compare. Here’s the result:

Non-rewritten URL (http://localhost/xsendfile_test/file.php):
[:error] [pid 10962] (2)No such file or directory: [client 127.0.0.1:38090] xsendfile: cannot open file: **/var/www/xsendfile_test/missing_target_file.mp4**

Rewritten URL (http://localhost/xsendfile_test/file.mp4):
[:error] [pid 10963] (2)No such file or directory: [client 127.0.0.1:56944] xsendfile: cannot open file: **redirect:/xsendfile_test/missing_target_file.mp4**

For some reason, when accessed via a non-redirected URL, XSendFile loads the file via the absolute path. When there’s a redirect involved, it ends up with only the path from the server’s web root directory, and breaks.

I’ve tried adding various combinations of path parts in the PHP script and in the htaccess, without success.

Any insight as to why the redirected URL is behaving differently, or what to do about it?

Side note on absolute paths and whitelisting:

One possible approach that I want to avoid is to set the absolute path in the PHP script, along with adding the path to the server’s XSendFilePath whitelist via the Apache config.

For the actual application this is not a workable solution, because it would mean that any server the code runs on has to have the configuration modified to accommodate the specific path. If this turns out to be necessary I will probably need to drop XSendFile altogether and use a different approach for sending files.

According to XSendFile docs, a file that is at or below the working directory in the filesystem can be accessed without whitelisting by using relative paths, which is the approach I want to stay with if possible.

(That said, the XSendFIle author helpfully responded to a previous SO post saying that how XSendFile constructs relative paths leads to potentially unexpected results. So maybe this is a quixotic quest and I need to find a different solution altogether…)

Any insights into this issue would be most welcome. Thank you!

How to specify php version for specific project in laravel

Here I’m working on a simple laravel project which uses php version of 7.1.3 and I have php version 8.1.2 installed on my computer.

How do I specify specific php version for different projects?

I tried to re-install php 7.1 version but I have other projects on my computer which uses 8 or higher.

Can I specify specific php version for different laravel projects?

How to bypass typo3 phar stream wrapper and use Php’s stream handlers in Joomla 4.2 winth php 8.1

I upgraded Joomla from 3.10.11 to 4.2. Since then I’m getting the error:
Uncaught TYPO3PharStreamWrapperException Unexpected file extension in “Phar://httpful.phar/……/Response.php”

I tried various forums facing quoting similar issue but could not find a solution.

Since phar deserialization vulnerability is fixed in php8+ , I want to** completely bypass typo 3’s phar stream wrapper and use php8.1’s built in stream handlers**.

How can I completely remove/bypass typo3-phar-stream-wrapper from Joomla4.2?

In PharExtensionInterceptor.php, I modified the function baseFileContainsPharExtension to return true even if file extension is php

 private function baseFileContainsPharExtension(string $path): bool
    {
        $invocation = Manager::instance()->resolve($path);
        if ($invocation === null) {
            return false;
        }
        $fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION);
        return strtolower($fileExtension) === 'phar';
    }
}

I modified it to:

 private function baseFileContainsPharExtension(string $path): bool
    {
        $invocation = Manager::instance()->resolve($path);
        if ($invocation === null) {
            return false;
        }
        $fileExtension = pathinfo($invocation->getBaseName(), PATHINFO_EXTENSION);
        return (strtolower($fileExtension) === 'phar'||strtolower($fileExtension) === 'php');
    }
}

This did not help either….
Phar stream handlers are already loaded, I checked in phpinfo()

The table header and body is not aligning in the 2nd page while creating pdf with TCPDF

I want to generate an invoice with TCPDF which contained a dynamic table depends on the size of the items. It works fine until the table size does not cross the first page. From the second page the table header shifts to the left which breaks the alignment between the table-header and the table-body. I don’t know how to fix this!
N.B: I do not have multiple table. It is a single table invoice.

<table style="font-family:Arial, Helvetica, sans-serif;border: 1px solid #ddd;padding: 3px">
    <thead>
    <tr style="line-height:20px;background-color:#F7F7F7">
    <th style="width: 40px; text-align: center;">#</th>
    <th style="width: 190px;">Product</th>
    <th style="width: 80px; text-align: center;">Quantity</th>
    <th style="width: 50px; text-align: center;">Unit</th>
    <th style="width: 80px; text-align: right;">Price (BDT)</th>
    <th style="width: 92px; text-align: right;">Amount (BDT)</th>
    </tr>
    </thead>
    <tbody>
     <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">01</td>
    <td style="width: 190px;"><b>Mouse</b><br><span style="font-size:10px">LOGITECH B175 WIRELESS MOUSE</span>
    </td>
    <td style="width: 80px; text-align: center;">5</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">500</td>
    <td style="width: 92px; text-align: right;">2500</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">02</td>
    <td style="width: 190px;"><b>Keyboard</b><br><span style="font-size:10px">Logitech G512 Lightsync RGB Mechanical USB Gaming Keyboard Black</span>
    </td>
    <td style="width: 80px; text-align: center;">13</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">3200</td>
    <td style="width: 92px; text-align: right;">3966</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">03</td>
    <td style="width: 190px;"><b>Pendrive</b><br><span style="font-size:10px">Adata 32GB USB 3.0</span>
    </td>
    <td style="width: 80px; text-align: center;">21</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">2750</td>
    <td style="width: 92px; text-align: right;">37750</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">04</td>
    <td style="width: 190px;"><b>Monitor</b><br><span style="font-size:10px">MSI G2412 23.8" 170Hz FHD IPS 1ms FreeSync Premium Gaming Monitor</span>
    </td>
    <td style="width: 80px; text-align: center;">6</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">24735</td>
    <td style="width: 92px; text-align: right;">148410</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">05</td>
    <td style="width: 190px;"><b>Headphone</b><br><span style="font-size:10px">Havit H2010d-Pro RGB Gaming Headphone</span>
    </td>
    <td style="width: 80px; text-align: center;">14</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">1150</td>
    <td style="width: 92px; text-align: right;">16100</td>
    </tr>
    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">06</td>
    <td style="width: 190px;"><b>Mouse</b><br><span style="font-size:10px">LOGITECH B175 WIRELESS MOUSE</span>
    </td>
    <td style="width: 80px; text-align: center;">5</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">500</td>
    <td style="width: 92px; text-align: right;">2500</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">07</td>
    <td style="width: 190px;"><b>Keyboard</b><br><span style="font-size:10px">Logitech G512 Lightsync RGB Mechanical USB Gaming Keyboard Black</span>
    </td>
    <td style="width: 80px; text-align: center;">13</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">3200</td>
    <td style="width: 92px; text-align: right;">3966</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">08</td>
    <td style="width: 190px;"><b>Pendrive</b><br><span style="font-size:10px">Adata 32GB USB 3.0</span>
    </td>
    <td style="width: 80px; text-align: center;">21</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">2750</td>
    <td style="width: 92px; text-align: right;">37750</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">09</td>
    <td style="width: 190px;"><b>Monitor</b><br><span style="font-size:10px">MSI G2412 23.8" 170Hz FHD IPS 1ms FreeSync Premium Gaming Monitor</span>
    </td>
    <td style="width: 80px; text-align: center;">6</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">24735</td>
    <td style="width: 92px; text-align: right;">148410</td>
    </tr>

    <tr style="border: 1px solid black!important;line-height: 2;">
    <td style="width: 40px; text-align: center; margin-top: 200px;">10</td>
    <td style="width: 190px;"><b>Headphone</b><br><span style="font-size:10px">Havit H2010d-Pro RGB Gaming Headphone</span>
    </td>
    <td style="width: 80px; text-align: center;">14</td>
    <td style="width: 50px; text-align: center;">Pcs</td>
    <td style="width: 80px; text-align: right;">1150</td>
    <td style="width: 92px; text-align: right;">16100</td>
    </tr>
    </tbody>
    </table>
  <style>
    th, td {
      border-bottom: 1px solid #e3e3e3;
      border-top: 1px solid #e3e3e3;
    }
    table tr th {
      color:black;
      font-weight:bold;
    }

    </style>

2nd page of the table

opencart-3.0.3.2 & images with system url instead of url by domain

I have the machine on windows 10, wamp with alias, OC 3.0.3.2 and misunderstanding of how the network works from a programmer’s point of view.

Uploaded image have a url like a “C:wamp64cgi-binsitenameimagecataloggoodsimage.png”, but should be like a “http://sitename/image/catalog/goods/image.png” and as a result of which image is not showed.

After installing OC I delete all default categories and product, made new category and create the product. Uploaded product image (i suspected not only images of product) is not show.

Moreover in admin panel path in left bottom corner of browser is correct, but image in time select it not showing too.
problem illustration

I tryed:

  • add in ./config.php and ./admin/config.php
define('HTTP_IMAGE', 'http://startshop/image/'); 
  • change ./catalog/model/tool/image.php
    by
if ($this->request->server['HTTPS']) {
    return $this->config->get('config_ssl') . 'image/' . $image_new; 
} else {
    return $this->config->get('config_url') . 'image/' . $image_new;
}

to

if ($this->request->server['HTTPS']) {
    return 'HTTP_IMAGE' . $new_image;  // return 'http://startshop' . $new_image; try too
} else {
    return 'HTTP_IMAGE' . $new_image;  // return 'http://startshop' . $new_image; try too
}

but how i understood this not work in OC_3

Also I tryed turn on .htaccess thinking what alias work is not correct, but nothing…

OC errors:

2023-03-09 14:19:15 - PHP Unknown:  The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead. in C:wamp64cgi-binstartshop.rusystemlibrarytemplateTwigAutoloader.php on line 12
2023-03-09 14:19:15 - PHP Unknown:  Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead. in C:wamp64cgi-binstartshop.rusystemlibrarytemplateTwigAutoloader.php on line 30
2023-03-09 14:19:15 - PHP Unknown:  Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead. in C:wamp64cgi-binstartshop.rusystemlibrarytemplateTwigAutoloader.php on line 30
2023-03-09 14:19:15 - PHP Unknown:  Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead. in C:wamp64cgi-binstartshop.rusystemlibrarytemplateTwigAutoloader.php on line 30
2023-03-09 14:19:15 - PHP Unknown:  Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead. in C:wamp64cgi-binstartshop.rusystemlibrarytemplateTwigAutoloader.php on line 30
2023-03-09 15:40:57 - PHP Warning:  googleshoppingGoogleshopping::integer(): Argument #1 ($product_id) must be passed by reference, value given in C:wamp64cgi-binstartshop.rusystemlibrarygoogleshoppinggoogleshopping.php on line 583
2023-03-09 15:40:57 - PHP Warning:  googleshoppingGoogleshopping::integer(): Argument #1 ($product_id) must be passed by reference, value given in C:wamp64cgi-binstartshop.rusystemlibrarygoogleshoppinggoogleshopping.php on line 583
2023-03-09 15:40:58 - PHP Warning:  Cannot modify header information - headers already sent by (output started at C:wamp64cgi-binstartshop.ruadminmodelextensionadvertisegoogle.php:341) in C:wamp64cgi-binstartshop.rusystemlibraryresponse.php on line 36
2023-03-10 9:33:28 - PHP Warning:  googleshoppingGoogleshopping::integer(): Argument #1 ($product_id) must be passed by reference, value given in C:wamp64cgi-binstartshop.rusystemlibrarygoogleshoppinggoogleshopping.php on line 583
2023-03-10 9:33:28 - PHP Warning:  Cannot modify header information - headers already sent by (output started at C:wamp64cgi-binstartshop.ruadminmodelextensionadvertisegoogle.php:341) in C:wamp64cgi-binstartshop.rusystemlibraryresponse.php on line 36
2023-03-10 12:42:29 - PHP Warning:  Trying to access array offset on value of type null in C:wamp64cgi-binstartshop.ruadmincontrollermarketplacemarketplace.php on line 1011
2023-03-10 12:42:29 - PHP Warning:  Trying to access array offset on value of type null in C:wamp64cgi-binstartshop.ruadmincontrollermarketplacemarketplace.php on line 1013
2023-03-14 8:28:07 - PHP Warning:  Trying to access array offset on value of type null in C:wamp64cgi-binstoragevendorscss.inc.php on line 1753

Please, sorry for my English and help me!

HTML Charges Calculation [closed]

I have the following code to do charges calculation.

Strictly confidential external

Rajitha Lakmal
to Rajitha
4 hours agoDetails
<!DOCTYPE html>
<html>
<head>
    <title>Loan Calculator</title>
</head>
<body>
    <h1>Loan Calculator</h1>
    <label for="loan-type">Select loan type:</label>
    <select id="loan-type">
        <option value="primary-commercial">Primary Mortgage - Commercial Loans</option>
        <option value="additional-commercial">Additional Mortgage - Commercial Loans</option>
        <option value="nivahana-housing">Primary and Additional Mortgages - Nivahana Housing Loans</option>
    </select>
    <br><br>
    <label for="loan-amount">Loan amount:</label>
    <input type="number" id="loan-amount">
    <br><br>
    <button onclick="calculateLoan()">Calculate</button>
    <br><br>
    <p id="result"></p>
    <script>
        function calculateLoan() {
            let loanType = document.getElementById("loan-type").value;
            let loanAmount = document.getElementById("loan-amount").value;
            let result = document.getElementById("result");
            if (loanType === "primary-commercial") {
                if (loanAmount < 1000000) {
                    result.innerHTML = "Total payment: " + (loanAmount * 0.01);
                } else if (loanAmount < 25000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 1000000) * 0.0075 + 10000);
                } else if (loanAmount < 50000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 25000000) * 0.006 + 190000);
                } else if (loanAmount < 75000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 50000000) * 0.006 + 340000);
                } else if (loanAmount < 100000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 75000000) * 0.005 + 465000);
                } else {
                    result.innerHTML = "Total payment: " + ((loanAmount - 100000000) * 0.001 + 527500);
                }
            } else if (loanType === "additional-commercial") {
                if (loanAmount < 25000000) {
                    result.innerHTML = "Total payment: " + (loanAmount * 0.004);
                } else if (loanAmount < 50000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 25000000) * 0.0025 + 100000);
                } else if (loanAmount < 100000000) {
                    result.innerHTML = "Total payment: " + ((loanAmount - 50000000) * 0.0015 + 162500);
                } else {
                    result.innerHTML = "Total payment: " + ((loanAmount - 100000000) * 0.00075 + 237500);
                }
            } else if (loanType === "nivahana-housing") {
                if (loanAmount < 25000000) {
                    result.innerHTML = "Total payment: " + (loanAmount * 0.0075);
                } else {
                    result.innerHTML = "Total payment: " + ((loanAmount - 25000000) * 0.0025 + 187500);
                }
            }
        }
    </script>
</body>
</html

I want to Add ” Declaration Charge – Rs. 1000.00 and get a sub total.

After sub total Add 2.56% as a Tax. After get total add 15% from that amount. And get total.

Is it really safe to output a variable with filter `raw` in Twig when the content is already escaped in the sql database?

I have post content in sql database where special char are already escaped with htmlspecialchars($content, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');.

I use the php template engine Twig to render my template (with no framework, only php vanilla). Here is my problem : Twig escape a second time the ampersand “&” char, which result in display ugly string in the webpage, like :
Here is a &lt;script&gt;window.alert(&quot;hello&quot;);&lt;/script&gt; test

When i use the filter raw in Twig, that solve the problem. But after some research, people say that it is not safe at all, but I can’t find a real solution.

So my question is : can I use raw filter in my case, because $content is already escaped by PHP ? Or there is a better and safer way to do this ?

I try to use raw filter and that work, also {% autoescape false %} work, but I want to be really sure that it is safe to render.

Can anyone help explain why this array has 2 array elements within a single array?

First time on here so I’ll try my best to provide as much info as possible. Also, my PHP knowledge is still not great so bear with my code.

Right now I have a foreach loop for a bunch of different sections of a XML file that I need to convert into an array and every other array is working as it should and outputting all of the specific data into the correct tables in the database.

foreach($branches as $branch_array){
connect($branch_array["url"] . '/property');


$property_list_xml = $request_refresh -> read_in_xml($url);
$properties = $request_refresh -> get_property_list($property_list_xml);

$property_details = array();
$property_paragraphs = array();
$property_files = array();
$property_bullets = array();
    
foreach($properties as $property_array){
    
    connect($property_array["url"]);
    $property_xml = $request_refresh -> read_in_xml($url);
    
    print_r($property_xml);
    
    $property_details[] = array(
    "id"=> (string)$property_xml["id"],
    "property_id"=> (string)$property_xml["propertyid"],
    "firm_id"=>(string)$property_xml["firmid"],
    "branch_id"=>(string)$property_xml["branchid"],
    "featured"=>(string)$property_xml["featured"],
    "name"=>(string)$property_xml->address->name,
    "street"=>(string)$property_xml->address->street,
    "locality"=>(string)$property_xml->address->locality,
    "town"=>(string)$property_xml->address->town,
    "county"=>(string)$property_xml->address->county,
    "postcode"=>(string)$property_xml->address->postcode,
    "custom_location"=>(string)$property_xml->address->custom_location,
    "display"=>(string)$property_xml->address->display,
    "price"=>(string)$property_xml->price,
    "rental_fees"=>(string)$property_xml->rentalfees,
    "lettings_fee"=>(string)$property_xml->lettingsfee,
    "rm_qualifier"=>(string)$property_xml->rm_qualifier,
    "available"=>(string)$property_xml->available,
    "uploaded"=>(string)$property_xml->uploaded,
    "longitude"=>(string)$property_xml->longitude,
    "latitude"=>(string)$property_xml->latitude,
    "web_status"=>(string)$property_xml->web_status,
    "custom_status"=>(string)$property_xml->custom_status,
    "type"=>(string)$property_xml->type,
    "furnished"=>(string)$property_xml->furnished,
    "rm_type"=>(string)$property_xml->rm_type,
    "let_bond"=>(string)$property_xml->let_bond,
    "rm_let_type_id"=>(string)$property_xml->rm_let_type_id,
    "bedrooms"=>(string)$property_xml->bedrooms,
    "receptions"=>(string)$property_xml->receptions,
    "bathrooms"=>(string)$property_xml->bathrooms,
    "userfield_1"=>(string)$property_xml->userfield_1,
    "userfield_2"=>(string)$property_xml->userfield_2,
    "sold_date"=>(string)$property_xml->sold_date,
    "instructed"=>(string)$property_xml->instructed,
    "let_date"=>(string)$property_xml->let_date,
    "sold_price"=>(string)$property_xml->sold_price,
    "garden"=>(string)$property_xml->garden,
    "parking"=>(string)$property_xml->parking,
    "new_build"=>(string)$property_xml->new_build,
    "commission"=>(string)$property_xml->commission,
    "tenure"=>(string)$property_xml->tenure,
    "description"=>(string)$property_xml->description,
    "energy_efficiency_current"=>(string)$property_xml->hip->energy_performance->energy_efficiency->current,
    "energy_efficiency_potential"=>(string)$property_xml->hip->energy_performance->energy_efficiency->potential,
    "environmental_impact_current"=>(string)$property_xml->hip->energy_performance->environmental_impact->current,
    "environmental_impact_potential"=>(string)$property_xml->hip->energy_performance->environmental_impact->potential,
    "council_tax_band"=>(string)$property_xml->council_tax->band,
    );
    
    if (isset($property_xml->bullets)){ 
        foreach($property_xml->bullets[0] as $bullet){
        
        $property_bullets[] = array(
        "property_id"=> (string)$property_xml["propertyid"],
        "bullet"=>(string)$bullet,
        );
            //print_r($bullet);
        }
    }

    if (isset($property_xml->paragraphs)){  
        foreach($property_xml->paragraphs[0] as $paragraph){
            
            //print_r($paragraph);
    
        $property_paragraphs[] = array(
        "property_id"=> (string)$property_xml["propertyid"],
        "id"=> (string)$paragraph->attributes()->id,
        "type"=>(string)$paragraph->attributes()->type,
        "name"=>(string)$paragraph->name,
        "file"=>(string)$paragraph->file,
        "metric"=>(string)$paragraph->dimensions->metric,
        "imperial"=>(string)$paragraph->dimensions->imperial,
        "mixed"=>(string)$paragraph->dimensions->mixed,
        "text"=>(string)$paragraph->text,

        );
        }
    }
    
    if (isset($property_xml->files)){   
        foreach($property_xml->files[0] as $files){ 
            
        $property_files[] = array(
        "property_id"=> (string)$property_xml["propertyid"],
        "id"=> (string)$files->attributes()->id,
        "file_type"=>(string)$files->attributes()->type,
        "name"=>(string)$files->name,
        "url"=>(string)$files->url,
        "updated"=>(string)$files->updated,
        );
        }
    }
}

    //print_r($property_xml);
    
}
    $five_arrays = array("branches"=> $branch_details,
                        "paragraphs"=> $property_paragraphs,
                        "properties"=> $property_details,
                        "bullets"=> $property_bullets,
                        "files"=> $property_files,
                       );

error_log("Connect to Database");
error_log("==================================================================");
$db_conn = $request_refresh -> connect_to_db($db_servername, $db_username, $db_password, $db_database);

error_log("Check Database connection is ok");
error_log("==================================================================");
$request_refresh -> check_db_connection_is_ok($db_conn);

error_log("Clear tables");
error_log("==================================================================");
$request_refresh -> clear_tables($table_names, $db_conn);

error_log("Add new records to tables");
error_log("==================================================================");
$failed_queries = $request_refresh -> add_new_records($db_conn, $table_names, $five_arrays);

The one giving me grief is the “bullet” since it gets all of the relevant data I require from the xml but then when it comes to getting it in the array, the second array element is the only one being uploaded to the table in the DB.

Array
(
    [0] => Array
        (
            [property_id] => 2412
            [bullet] => Modern Office Suites
        )

    [1] => Array
        (
            [property_id] => 2412
            [bullet] => Lift
        )

    [2] => Array
        (
            [property_id] => 2412
            [bullet] => Car Parking Space
        )

    [3] => Array
        (
            [property_id] => 3001
            [bullet] => Luxury Lodge
        )

    [4] => Array
        (
            [property_id] => 3001
            [bullet] => 2 Bedrooms
        )

    [5] => Array
        (
            [property_id] => 3001
            [bullet] => Small Garden
        )

    [6] => Array
        (
            [property_id] => 3001
            [bullet] => 2 Parking Spaces
        )

    [7] => Array
        (
            [property_id] => 3001
            [bullet] => Viewing Highly Recommended
        )

    [8] => Array
        (
            [property_id] => 3051
            [bullet] => 3 Bedrooms
        )

    [9] => Array
        (
            [property_id] => 3051
            [bullet] => uPVC double glazing
        )

    [10] => Array
        (
            [property_id] => 3051
            [bullet] => Gas fired central heating
        )

    [11] => Array
        (
            [property_id] => 3051
            [bullet] => Parking
        )

    [12] => Array
        (
            [property_id] => 3051
            [bullet] => Garden
        )

    [13] => Array
        (
            [property_id] => 3351
            [bullet] => 3 Bedroom Cottage
        )

    [14] => Array
        (
            [property_id] => 3351
            [bullet] => Central Heating
        )

    [15] => Array
        (
            [property_id] => 3351
            [bullet] => Double Glazing
        )

    [16] => Array
        (
            [property_id] => 3351
            [bullet] => Ideal First Time Buy
        )

    [17] => Array
        (
            [property_id] => 3146
            [bullet] => 2 Bedrooms
        )

    [18] => Array
        (
            [property_id] => 3146
            [bullet] => Attic Room
        )

    [19] => Array
        (
            [property_id] => 3146
            [bullet] => uPVC double Glazing
        )

    [20] => Array
        (
            [property_id] => 3146
            [bullet] => Gas Fired Central Heating
        )

    [21] => Array
        (
            [property_id] => 3146
            [bullet] => Balcony enjoying views
        )

    [22] => Array
        (
            [property_id] => 3146
            [bullet] => Viewing Recommended
        )

    [23] => Array
        (
            [property_id] => 3701
            [bullet] => 2 Bedrooms
        )

    [24] => Array
        (
            [property_id] => 3701
            [bullet] => Balcony
        )

    [25] => Array
        (
            [property_id] => 3701
            [bullet] => Central Heating
        )

    [26] => Array
        (
            [property_id] => 3701
            [bullet] => Parking Space
        )

    [27] => Array
        (
            [property_id] => 3701
            [bullet] => Close to town centre
        )

    [28] => Array
        (
            [property_id] => 3701
            [bullet] => Viewing Recommended
        )

    [29] => Array
        (
            [property_id] => 3265
            [bullet] => 2 bedrooms
        )

    [30] => Array
        (
            [property_id] => 3265
            [bullet] => Immaculately presented
        )

    [31] => Array
        (
            [property_id] => 3265
            [bullet] => Courtyard Garden
        )

    [32] => Array
        (
            [property_id] => 3265
            [bullet] => uPVC double glazing
        )

    [33] => Array
        (
            [property_id] => 3265
            [bullet] => Viewing Recommended
        )

    [34] => Array
        (
            [property_id] => 1876
            [bullet] => Stone built end of terrace cottage
        )

    [35] => Array
        (
            [property_id] => 1876
            [bullet] => 3 Bedrooms
        )

    [36] => Array
        (
            [property_id] => 1876
            [bullet] => Sympathetically improved & upgraded
        )

    [37] => Array
        (
            [property_id] => 1876
            [bullet] => Original character features
        )

    [38] => Array
        (
            [property_id] => 1876
            [bullet] => Recessed stone fireplaces
        )

    [39] => Array
        (
            [property_id] => 1876
            [bullet] => Garden
        )

    [40] => Array
        (
            [property_id] => 1876
            [bullet] => Views of Snowdonia
        )

    [41] => Array
        (
            [property_id] => 3541
            [bullet] => 2 Bedroom
        )

    [42] => Array
        (
            [property_id] => 3541
            [bullet] => Detached House
        )

    [43] => Array
        (
            [property_id] => 3541
            [bullet] => Magical Setting
        )

    [44] => Array
        (
            [property_id] => 3541
            [bullet] => Character Features
        )

    [45] => Array
        (
            [property_id] => 3541
            [bullet] => Oil Fired Central Heating
        )

    [46] => Array
        (
            [property_id] => 3541
            [bullet] => Double Glazing
        )

    [47] => Array
        (
            [property_id] => 3541
            [bullet] => Viewing Recommended.
        )

    [48] => Array
        (
            [property_id] => 2270
            [bullet] => Retail Premises
        )

    [49] => Array
        (
            [property_id] => 2270
            [bullet] => 5 Self Contained Units
        )

    [50] => Array
        (
            [property_id] => 2270
            [bullet] => Central Location
        )

    [51] => Array
        (
            [property_id] => 2270
            [bullet] => Rear Access
        )

    [52] => Array
        (
            [property_id] => 2270
            [bullet] => Small Parking Area
        )

    [53] => Array
        (
            [property_id] => 3190
            [bullet] => Public House and Restaurant
        )

    [54] => Array
        (
            [property_id] => 3190
            [bullet] => Set in Large Plot
        )

    [55] => Array
        (
            [property_id] => 3190
            [bullet] => Parking
        )

    [56] => Array
        (
            [property_id] => 3190
            [bullet] => Riverside Beer Garden
        )

    [57] => Array
        (
            [property_id] => 3190
            [bullet] => 4 Bedroom Owners Accommodation
        )

    [58] => Array
        (
            [property_id] => 3190
            [bullet] => Viewing Highly Recommended
        )

    [59] => Array
        (
            [property_id] => 814
            [bullet] => Established B&B and Cafe
        )

    [60] => Array
        (
            [property_id] => 814
            [bullet] => Popular village location
        )

    [61] => Array
        (
            [property_id] => 814
            [bullet] => Snowdonia National Park
        )

    [62] => Array
        (
            [property_id] => 814
            [bullet] => 5 letting rooms (3 En suite)
        )

    [63] => Array
        (
            [property_id] => 814
            [bullet] => 4 owners bedrooms
        )

    [64] => Array
        (
            [property_id] => 814
            [bullet] => Public car park
        )

    [65] => Array
        (
            [property_id] => 814
            [bullet] => Going concern
        )

)
Array
(
    [0] => Array
        (
            [property_id] => 1632
            [bullet] => Detached bungalow
        )

    [1] => Array
        (
            [property_id] => 1632
            [bullet] => 4 Bedrooms
        )

    [2] => Array
        (
            [property_id] => 1632
            [bullet] => Rural setting
        )

    [3] => Array
        (
            [property_id] => 1632
            [bullet] => Views
        )

    [4] => Array
        (
            [property_id] => 1632
            [bullet] => Gardens
        )

)

It’s only up until 65 and then the second element is opened and this is the only one that is being uploaded.

This below is my expectation:

Array
(
    [0] => Array
        (
            [property_id] => 2412
            [bullet] => Modern Office Suites
        )

    [1] => Array
        (
            [property_id] => 2412
            [bullet] => Lift
        )

    [2] => Array
        (
            [property_id] => 2412
            [bullet] => Car Parking Space
        )

    [3] => Array
        (
            [property_id] => 3001
            [bullet] => Luxury Lodge
        )

    [4] => Array
        (
            [property_id] => 3001
            [bullet] => 2 Bedrooms
        )

    [5] => Array
        (
            [property_id] => 3001
            [bullet] => Small Garden
        )

    [6] => Array
        (
            [property_id] => 3001
            [bullet] => 2 Parking Spaces
        )

    [7] => Array
        (
            [property_id] => 3001
            [bullet] => Viewing Highly Recommended
        )

    [8] => Array
        (
            [property_id] => 3051
            [bullet] => 3 Bedrooms
        )

    [9] => Array
        (
            [property_id] => 3051
            [bullet] => uPVC double glazing
        )

    [10] => Array
        (
            [property_id] => 3051
            [bullet] => Gas fired central heating
        )

    [11] => Array
        (
            [property_id] => 3051
            [bullet] => Parking
        )

    [12] => Array
        (
            [property_id] => 3051
            [bullet] => Garden
        )

    [13] => Array
        (
            [property_id] => 3351
            [bullet] => 3 Bedroom Cottage
        )

    [14] => Array
        (
            [property_id] => 3351
            [bullet] => Central Heating
        )

    [15] => Array
        (
            [property_id] => 3351
            [bullet] => Double Glazing
        )

    [16] => Array
        (
            [property_id] => 3351
            [bullet] => Ideal First Time Buy
        )

    [17] => Array
        (
            [property_id] => 3146
            [bullet] => 2 Bedrooms
        )

    [18] => Array
        (
            [property_id] => 3146
            [bullet] => Attic Room
        )

    [19] => Array
        (
            [property_id] => 3146
            [bullet] => uPVC double Glazing
        )

    [20] => Array
        (
            [property_id] => 3146
            [bullet] => Gas Fired Central Heating
        )

    [21] => Array
        (
            [property_id] => 3146
            [bullet] => Balcony enjoying views
        )

    [22] => Array
        (
            [property_id] => 3146
            [bullet] => Viewing Recommended
        )

    [23] => Array
        (
            [property_id] => 3701
            [bullet] => 2 Bedrooms
        )

    [24] => Array
        (
            [property_id] => 3701
            [bullet] => Balcony
        )

    [25] => Array
        (
            [property_id] => 3701
            [bullet] => Central Heating
        )

    [26] => Array
        (
            [property_id] => 3701
            [bullet] => Parking Space
        )

    [27] => Array
        (
            [property_id] => 3701
            [bullet] => Close to town centre
        )

    [28] => Array
        (
            [property_id] => 3701
            [bullet] => Viewing Recommended
        )

    [29] => Array
        (
            [property_id] => 3265
            [bullet] => 2 bedrooms
        )

    [30] => Array
        (
            [property_id] => 3265
            [bullet] => Immaculately presented
        )

    [31] => Array
        (
            [property_id] => 3265
            [bullet] => Courtyard Garden
        )

    [32] => Array
        (
            [property_id] => 3265
            [bullet] => uPVC double glazing
        )

    [33] => Array
        (
            [property_id] => 3265
            [bullet] => Viewing Recommended
        )

    [34] => Array
        (
            [property_id] => 1876
            [bullet] => Stone built end of terrace cottage
        )

    [35] => Array
        (
            [property_id] => 1876
            [bullet] => 3 Bedrooms
        )

    [36] => Array
        (
            [property_id] => 1876
            [bullet] => Sympathetically improved & upgraded
        )

    [37] => Array
        (
            [property_id] => 1876
            [bullet] => Original character features
        )

    [38] => Array
        (
            [property_id] => 1876
            [bullet] => Recessed stone fireplaces
        )

    [39] => Array
        (
            [property_id] => 1876
            [bullet] => Garden
        )

    [40] => Array
        (
            [property_id] => 1876
            [bullet] => Views of Snowdonia
        )

    [41] => Array
        (
            [property_id] => 3541
            [bullet] => 2 Bedroom
        )

    [42] => Array
        (
            [property_id] => 3541
            [bullet] => Detached House
        )

    [43] => Array
        (
            [property_id] => 3541
            [bullet] => Magical Setting
        )

    [44] => Array
        (
            [property_id] => 3541
            [bullet] => Character Features
        )

    [45] => Array
        (
            [property_id] => 3541
            [bullet] => Oil Fired Central Heating
        )

    [46] => Array
        (
            [property_id] => 3541
            [bullet] => Double Glazing
        )

    [47] => Array
        (
            [property_id] => 3541
            [bullet] => Viewing Recommended.
        )

    [48] => Array
        (
            [property_id] => 2270
            [bullet] => Retail Premises
        )

    [49] => Array
        (
            [property_id] => 2270
            [bullet] => 5 Self Contained Units
        )

    [50] => Array
        (
            [property_id] => 2270
            [bullet] => Central Location
        )

    [51] => Array
        (
            [property_id] => 2270
            [bullet] => Rear Access
        )

    [52] => Array
        (
            [property_id] => 2270
            [bullet] => Small Parking Area
        )

    [53] => Array
        (
            [property_id] => 3190
            [bullet] => Public House and Restaurant
        )

    [54] => Array
        (
            [property_id] => 3190
            [bullet] => Set in Large Plot
        )

    [55] => Array
        (
            [property_id] => 3190
            [bullet] => Parking
        )

    [56] => Array
        (
            [property_id] => 3190
            [bullet] => Riverside Beer Garden
        )

    [57] => Array
        (
            [property_id] => 3190
            [bullet] => 4 Bedroom Owners Accommodation
        )

    [58] => Array
        (
            [property_id] => 3190
            [bullet] => Viewing Highly Recommended
        )

    [59] => Array
        (
            [property_id] => 814
            [bullet] => Established B&B and Cafe
        )

    [60] => Array
        (
            [property_id] => 814
            [bullet] => Popular village location
        )

    [61] => Array
        (
            [property_id] => 814
            [bullet] => Snowdonia National Park
        )

    [62] => Array
        (
            [property_id] => 814
            [bullet] => 5 letting rooms (3 En suite)
        )

    [63] => Array
        (
            [property_id] => 814
            [bullet] => 4 owners bedrooms
        )

    [64] => Array
        (
            [property_id] => 814
            [bullet] => Public car park
        )

    [65] => Array
        (
            [property_id] => 814
            [bullet] => Going concern
        )

    [66] => Array
        (
            [property_id] => 1632
            [bullet] => Detached bungalow
        )

    [67] => Array
        (
            [property_id] => 1632
            [bullet] => 4 Bedrooms
        )

    [68] => Array
        (
            [property_id] => 1632
            [bullet] => Rural setting
        )

    [69] => Array
        (
            [property_id] => 1632
            [bullet] => Views
        )

    [70] => Array
        (
            [property_id] => 1632
            [bullet] => Gardens
        )

)

This is what I want since this will upload all of my data into the table. I just can’t understand why it’s only happening to this array and not the others since there all made the same way.

ftp_put(): php_connect_nonb() failed: Operation now in progress (115)

Ok so i have a cron page that I run on my server that does the following

  1. creates backup of the database
  2. puts the created SQL into a .gz archive
  3. uploads the archive to my ftp server (synology NAS DS220j)

But for some reason I’m getting the following errors when it was working just fine. Only thing that has changed is the router, ports have been setup and I can connect to the FTP server, with filezilla iand I can upload and download as normal from it.

The database db_name was successfully stored in the following path root_to_public_html/backup/backup-2023-03-14.sql

Warning: ftp_put(): php_connect_nonb() failed: Operation now in progress (115) in root_to_public_html/backup.php on line 110

Warning: ftp_put(): Type set to I. in root_to_public_html/backup.php on line 110
Error: While uploading backup-2023-03-14.sql.gz to 51.52.230.117.

<?php
//display errors
error_reporting(E_ALL); 
ini_set("display_errors", 1);

$core_path = dirname(__FILE__);
//Enter your database information here and the name of the backup file
$mysqlDatabaseName ="db_name";
$mysqlUserName ="db_user";
$mysqlPassword ="db_pass";
$mysqlHostName ="localhost";
$mysqlExportPath = "{$core_path}/backup/backup-".date('Y-m-d').".sql";

//----------------------------------------------------------------
//local testing
//----------------------------------------------------------------
//$mysqlUserName ="root";
//$mysqlPassword ="";


$conn = new mysqli($mysqlHostName, $mysqlUserName, $mysqlPassword, $mysqlDatabaseName);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//Please do not change the following points
//Export of the database and output of the status
$output=array();
$command='mysqldump --opt -h' .$mysqlHostName .' -u' .$mysqlUserName .' -p' .$mysqlPassword .' ' .$mysqlDatabaseName .' > '.$mysqlExportPath;
exec($command,$output,$worked);
switch($worked){
case 0:
echo 'The database <b>' .$mysqlDatabaseName .'</b> was successfully stored in the following path '.getcwd().$mysqlExportPath .'</b><br>';
    $sql ="INSERT INTO db_backup (backup_date) VALUES ('".date('Y-m-d')."')";
    $resultSql = $conn->query($sql);
break;
case 1:
echo 'An error occurred when exporting <b>' .$mysqlDatabaseName .'</b> zu '.getcwd().'/' .$mysqlExportPath .'</b><br>';
break;
case 2:
echo 'An export error has occurred, please check the following information: <br/><br/><table><tr><td>MySQL Database Name:</td><td><b>' .$mysqlDatabaseName .'</b></td></tr><tr><td>MySQL User Name:</td><td><b>' .$mysqlUserName .'</b></td></tr><tr><td>MySQL Password:</td><td><b>NOTSHOWN</b></td></tr><tr><td>MySQL Host Name:</td><td><b>' .$mysqlHostName .'</b></td></tr></table><br>';
break;
}

//----------------------------------------------------------------
//Set defaults
//----------------------------------------------------------------

set_time_limit(0);
$ftp_count                      = -1;

//----------------------------------------------------------------
//FTP credentials
//----------------------------------------------------------------
//Configure credentials of one or more ftp server to transfer the backup

//FTP 1
$ftp_count++;
$ftp[$ftp_count]['ftps']                = false;
$ftp[$ftp_count]['ftp_server']          = "ftp.server.co.uk";
$ftp[$ftp_count]['ftp_user']            = "user";
$ftp[$ftp_count]['ftp_password']        = "pass";
$ftp[$ftp_count]['ftp_passive_mode']    = true;
$ftp[$ftp_count]['ftp_remote_folder']   = "/";  //e.g. /mysite/backups


//----------------------------------------------------------------
//Interate over all databases
//----------------------------------------------------------------
if (file_exists("{$mysqlExportPath}".".gz")){
    unlink("{$mysqlExportPath}".".gz"); 
}

$mysqlExportPath = "{$core_path}/backup/backup-".date('Y-m-d').".sql";
exec("gzip {$mysqlExportPath}");

$db_item['sql_file'] = "backup-".date('Y-m-d').".sql";


//----------------------------------------------------------------
//FTP transfer: Transfer sql dump to the configured ftp servers
//----------------------------------------------------------------

if($ftp_count >= 0)
{
    foreach($ftp as $ftp_item)
    {
        //Initiate connection
        if($ftp_item['ftps'])
            $connection_id = ftp_ssl_connect($ftp_item['ftp_server']);
        else
            $connection_id = ftp_connect($ftp_item['ftp_server']);

        if(!$connection_id)
            echo "Error: Can't connect to {$ftp_item['ftp_server']}";


        //Login with user and password
        if($connection_id){
            $login_result = ftp_login($connection_id, $ftp_item['ftp_user'], $ftp_item['ftp_password']);
        }

        if(!$login_result)
            echo "Error: Login wrong for {$ftp_item['ftp_server']}";


        //Passive mode?
        ftp_pasv($connection_id, $ftp_item['ftp_passive_mode']);

        //Upload file to ftp
        if (!ftp_put($connection_id, $ftp_item['ftp_remote_folder']."backup-".date('Y-m-d').".sql.gz", $mysqlExportPath.'.gz', FTP_BINARY))
        {
            echo "Error: While uploading {$db_item['sql_file']}.gz to {$ftp_item['ftp_server']}.";
        }

        //Close ftp connection
        ftp_close($connection_id);
    }
}

?>

I’ve had a look through here but all i can see if people advising to use ftp_pasv() which I do as you can see in the code.

ive also tried adding

ftp_set_option($connection_id, FTP_USEPASVADDRESS, false);

before

ftp_pasv($connection_id, $ftp_item['ftp_passive_mode']);

I’m totally baffled as to why it wont work 🙁

Laravel Yajra Datatables Individual Column Search Doesn’t Work

In my previous code, I could use datatable with client side processing with such query:

Penulis::all();

but since there are huge amount of data exist, the load time is so long. so, I tried to use server side processing. here’s my code:

The Table

<div class="table-responsive">
        <table class="table table-striped" id="table_penulis">
            <thead>
                <tr>
                    <th>No</th>
                    <th>Aksi</th>
                    <th>namadepan</th>
                    <th>namatengah</th>
                    <th>namabelakang</th>
                    <th>gelardepan</th>
                    <th>gelarbelakang</th>
                    <th>jeniskelamin</th>
                    <th>tempatlahir</th>
                    <th>tanggallahir</th>
                    <th>jalan</th>
                    <th>kelurahan</th>
                    <th>rt</th>
                    <th>rw</th>
                    <th>kecamatan</th>
                    <th>kota</th>
                    <th>provinsi</th>
                    <th>kodepos</th>
                    <th>telp</th>
                    <th>email</th>
                    <th>bank</th>
                    <th>norek</th>
                    <th>namarek</th>
                    <th>pendidikanterakhir</th>
                    <th>pekerjaan</th>
                    <th>jabatan</th>
                    <th>namaperusahaan</th>
                    <th>jabatanfungsional</th>
                    <th>jabatanstruktural</th>
                    <th>prodi</th>
                    <th>jurusan</th>
                    <th>fakultas</th>
                    <th>linkedin</th>
                    <th>facebook</th>
                    <th>instagram</th>
                    <th>tiktok</th>
                    <th>namasaksi1</th>
                    <th>emailsaksi1</th>
                    <th>telpsaksi1</th>
                    <th>namasaksi2</th>
                    <th>emailsaksi2</th>
                    <th>telpsaksi2</th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <th></th>
                    <th></th>
                    <th class="th">namadepan</th>
                    <th class="th">namatengah</th>
                    <th class="th">namabelakang</th>
                    <th class="th">gelardepan</th>
                    <th class="th">gelarbelakang</th>
                    <th class="th">jeniskelamin</th>
                    <th class="th">tempatlahir</th>
                    <th class="th">tanggallahir</th>
                    <th class="th">jalan</th>
                    <th class="th">kelurahan</th>
                    <th class="th">rt</th>
                    <th class="th">rw</th>
                    <th class="th">kecamatan</th>
                    <th class="th">kota</th>
                    <th class="th">provinsi</th>
                    <th class="th">kodepos</th>
                    <th class="th">telp</th>
                    <th class="th">email</th>
                    <th class="th">bank</th>
                    <th class="th">norek</th>
                    <th class="th">namarek</th>
                    <th class="th">pendidikanterakhir</th>
                    <th class="th">pekerjaan</th>
                    <th class="th">jabatan</th>
                    <th class="th">namaperusahaan</th>
                    <th class="th">jabatanfungsional</th>
                    <th class="th">jabatanstruktural</th>
                    <th class="th">prodi</th>
                    <th class="th">jurusan</th>
                    <th class="th">fakultas</th>
                    <th class="th">linkedin</th>
                    <th class="th">facebook</th>
                    <th class="th">instagram</th>
                    <th class="th">tiktok</th>
                    <th class="th">namasaksi1</th>
                    <th class="th">emailsaksi1</th>
                    <th class="th">telpsaksi1</th>
                    <th class="th">namasaksi2</th>
                    <th class="th">emailsaksi2</th>
                    <th class="th">telpsaksi2</th>
                </tr>
            </tfoot>
            <tbody></tbody>
        </table>
    </div>

the Datatable (JQuery)

$('#table_penulis').DataTable({
        processing  : true,
        serverSide  : true,
        responsive  : true,
        dom         : 'Bfrtip',
        paging      : true,
        ajax: "/api/master-penulis-datatable",
        columns: [
            {data  : 'DT_RowIndex',        name  : 'DT_RowIndex', orderable: false, searchable: false},
            {data  : 'action',             name  : 'action',      orderable: false, searchable: false},
            {data  : 'namadepan',          name  : 'namadepan'                                       },
            {data  : 'namatengah',         name  : 'namatengah'                                      },
            {data  : 'namabelakang',       name  : 'namabelakang'                                    },
            {data  : 'gelardepan',         name  : 'gelardepan'                                      },
            {data  : 'gelarbelakang',      name  : 'gelarbelakang'                                   },
            {data  : 'jeniskelamin',       name  : 'jeniskelamin'                                    },
            {data  : 'tempatlahir',        name  : 'tempatlahir'                                     },
            {data  : 'tanggallahir',       name  : 'tanggallahir'                                    },
            {data  : 'jalan',              name  : 'jalan'                                           },
            {data  : 'kelurahan',          name  : 'kelurahan'                                       },
            {data  : 'rt',                 name  : 'rt'                                              },
            {data  : 'rw',                 name  : 'rw'                                              },
            {data  : 'kecamatan',          name  : 'kecamatan'                                       },
            {data  : 'kota',               name  : 'kota'                                            },
            {data  : 'provinsi',           name  : 'provinsi'                                        },
            {data  : 'kodepos',            name  : 'kodepos'                                         },
            {data  : 'telp',               name  : 'telp'                                            },
            {data  : 'email',              name  : 'email'                                           },
            {data  : 'bank',               name  : 'bank'                                            },
            {data  : 'norek',              name  : 'norek'                                           },
            {data  : 'namarek',            name  : 'namarek'                                         },
            {data  : 'pendidikanterakhir', name  : 'pendidikanterakhir'                              },
            {data  : 'pekerjaan',          name  : 'pekerjaan'                                       },
            {data  : 'jabatan',            name  : 'jabatan'                                         },
            {data  : 'namaperusahaan',     name  : 'namaperusahaan'                                  },
            {data  : 'jabatanfungsional',  name  : 'jabatanfungsional'                               },
            {data  : 'jabatanstruktural',  name  : 'jabatanstruktural'                               },
            {data  : 'prodi',              name  : 'prodi'                                           },
            {data  : 'jurusan',            name  : 'jurusan'                                         },
            {data  : 'fakultas',           name  : 'fakultas'                                        },
            {data  : 'linkedin',           name  : 'linkedin'                                        },
            {data  : 'facebook',           name  : 'facebook'                                        },
            {data  : 'instagram',          name  : 'instagram'                                       },
            {data  : 'tiktok',             name  : 'tiktok'                                          },
            {data  : 'namasaksi1',         name  : 'namasaksi1'                                      },
            {data  : 'emailsaksi1',        name  : 'emailsaksi1'                                     },
            {data  : 'telpsaksi1',         name  : 'telpsaksi1'                                      },
            {data  : 'namasaksi2',         name  : 'namasaksi2'                                      },
            {data  : 'emailsaksi2',        name  : 'emailsaksi2'                                     },
            {data  : 'telpsaksi2',         name  : 'telpsaksi2'                                      },
        ],
        initComplete: function() {
            this.api().columns().every(function() {
                var that = this;

                $('input', this.footer()).on('keyup change clear', function() {
                    if (that.search() !== this.value) {
                        that.search(this.value).draw();
                    }
                });

                $('#table_penulis tfoot .th').each(function() {
                    var title = $(this).text();
                    $(this).html('<input type="text" class="form-control rounded shadow" placeholder="search" />');
                });
            });
        },
    });

and here’s the Controller

$data  = Penulis::query();
    return $dataTables->eloquent($data)
            ->addIndexColumn()
            ->addColumn('action', function($row){
                $btn = '<btn class="btn btn-info btn-sm" data-id="'. $row->id .'"><i class="bi bi-eye text-white"></i></btn>';
                return $btn;
            })
            ->rawColumns(['action'])
            ->toJson();

I’m using postgresql, here’s the DDL:

CREATE TABLE "royalti"."writers" (
"namadepan" VARCHAR ( 50 ) COLLATE "pg_catalog"."default",
"namatengah" VARCHAR ( 50 ) COLLATE "pg_catalog"."default",
"namabelakang" VARCHAR ( 50 ) COLLATE "pg_catalog"."default",
"gelardepan" VARCHAR ( 20 ) COLLATE "pg_catalog"."default",
"gelarbelakang" VARCHAR ( 50 ) COLLATE "pg_catalog"."default",
"jeniskelamin" CHAR ( 1 ) COLLATE "pg_catalog"."default",
"tempatlahir" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"tanggallahir" DATE,
"jalan" VARCHAR ( 255 ) COLLATE "pg_catalog"."default",
"kelurahan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"rt" VARCHAR ( 10 ) COLLATE "pg_catalog"."default",
"rw" VARCHAR ( 10 ) COLLATE "pg_catalog"."default",
"kecamatan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"kota" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"provinsi" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"kodepos" VARCHAR ( 10 ) COLLATE "pg_catalog"."default",
"telp" VARCHAR ( 20 ) COLLATE "pg_catalog"."default",
"email" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"norek" VARCHAR ( 20 ) COLLATE "pg_catalog"."default",
"namarek" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"pendidikanterakhir" VARCHAR ( 10 ) COLLATE "pg_catalog"."default",
"pekerjaan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"jabatan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"namaperusahaan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"jabatanfungsional" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"jabatanstruktural" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"prodi" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"jurusan" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"fakultas" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"linkedin" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"facebook" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"instagram" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"tiktok" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"namasaksi1" VARCHAR ( 255 ) COLLATE "pg_catalog"."default",
"emailsaksi1" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"telpsaksi1" VARCHAR ( 20 ) COLLATE "pg_catalog"."default",
"namasaksi2" VARCHAR ( 255 ) COLLATE "pg_catalog"."default",
"emailsaksi2" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
"telpsaksi2" VARCHAR ( 20 ) COLLATE "pg_catalog"."default",
"id" INT8 NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 MINVALUE 1 MAXVALUE 9223372036854775807 START 1 CACHE 1 ),
"bank" VARCHAR ( 100 ) COLLATE "pg_catalog"."default",
CONSTRAINT "writers_pkey" PRIMARY KEY ( "id" ));
ALTER TABLE "royalti"."writers" OWNER TO "postgres";

The Client Side can perform individual column search, but since I’m using this type of serverside, the search doesn’t work.

laravel10 upgrade vite revert to laravel-mix problem

I’m upgrading a fairly well advanced project from laravel 9 to laravel 10. Had a few issues but mostly these are resolved.

When I now do tests in the browser it is saying Vite manifest not found I’ve removed vite from npm removed the vite js file and reinstalled laravel-mix via npm. When i run npm run dev it compiles successfully using mix but when I reload the page it says vite manifest not found.

I followed the following tutorials:
https://github.com/laravel/vite-plugin/blob/main/UPGRADE.md#migrating-from-vite-to-laravel-mix (near bottom of page)
https://github.com/laravel/vite-plugin/blob/main/UPGRADE.md#migrating-from-vite-to-laravel-mix

Any ideas? How is my browser thinking I’m using vite? The correct assets are created via mix but this is not used.

thanks

Is there a way to pass arguments to WordPress template (w/o get_template_part())

So, I need to pass arguments to WordPress template (e.g. index.php or single.php) like this:

<?php
/**
 * File ./single.php
 *
 * @var string $foo
 * @var int    $bar
 */

echo $foo; // like that?
echo $bar;
echo $args['foo']; // or maybe this way?
echo $args['bar'];

Just to clarify: I DO NOT need to pass that arguments to get_template_part() function, I need them in “main” template, that loads up via WordPress template hierarchy. If I get this correctly, the only step before template renders that I can affect on is functions.php. So, is there a way to pass arguments (to satisfy MVC conception better), or should I use some functions, methods, maybe do_action() and apply_filter() hooks?

Cannot load resource “../src/Controller/”. Make sure there is a loader supporting the “attribute” type. ExceptionLogs 1Stack Trace SymfonyComponentC

Cannot load resource “../src/Controller/”. Make sure there is a loader supporting the “attribute” type.
ExceptionLogs 1Stack Trace
SymfonyComponentConfigException
LoaderLoadException
in C:wamp64wwwmy_project_symfony_dalvendorsymfonyconfigLoaderLoader.php (line 71)
} $loader = null === $this->resolver ? false : $this->resolver->resolve($resource, $type); if (false === $loader) { throw new LoaderLoadException($resource, null, 0, null, $type); } return $loader; }}

Unserialize MYSQL Data And Export As CSV

Ok I have MYSQL data and I can perfectly export it to CSV. Problem here is one of the columns have serialized data and when I export, it shows as serialized. I have tried unsterilized function of PHP but it doesn’t seem to work.

Please find below code to export to CSV and column having serialized data is fine_type.

Thanks

Code For Export to CSV

<?php 
// Load the database configuration file 
include 'connect.php';
//$h=$_REQUEST['inspector_name'];
//$emp_numberd=$_REQUEST['datepicker'];


// Filter the excel data 
function filterData(&$str){ 
    $str = preg_replace("/t/", "\t", $str); 
    $str = preg_replace("/r?n/", "\n", $str); 
    if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; 
} 
 
// Excel file name for download 
$fileName = "members-data_" . date('d-m-Y') . ".xls"; 
 
// Column names 
$fields = array('اسم المحل','.الرخصة','اسم المفتش','Fine Date','Fine Details','المستفيد الحقيقي'); 
 
// Display column names as first row 
$excelData = implode("t", array_values($fields)) . "n"; 
 
// Fetch records from database 
$query = $link->query("SELECT  * FROM fine_controls WHERE str_to_date(fine_date, '%d-%m-%Y') between str_to_date('01-11-2022', '%d-%m-%Y') and str_to_date('10-03-2023', '%d-%m-%Y') order by id desc"); 

if($query->num_rows > 0){ 
    // Output each row of the data 
    while($row = $query->fetch_assoc()){
        
        $status = ($row['statuse'] == 1)?'Active':'Inactive'; 
        $lineData = array($row['shopname'],$row['license'],$row['inspector_name'],$row['fine_date'],$row['fine_type'],$row['beneficiary']); 
        array_walk($lineData, 'filterData'); 
        $excelData .= implode("t", array_values($lineData)) . "n"; 
    } 
}else{ 
    $excelData .= 'No records found...'. "n"; 
} 
 
// Headers for download 
header("Content-Type: application/vnd.ms-excel"); 
header("Content-Disposition: attachment; filename="$fileName""); 
 print chr(255) . chr(254).mb_convert_encoding($excelData, 'UTF-16LE', 'UTF-8');
// Render excel data 
//echo $excelData; 
 
exit;

Changes I have already tried

if($query->num_rows > 0){ 
        // Output each row of the data 
        while($row = $query->fetch_assoc()){
 $data=unserialize($row['fine_type']);
            
            $status = ($row['statuse'] == 1)?'Active':'Inactive'; 
            $lineData = array($row['shopname'],$row['license'],$row['inspector_name'],$data,$row['fine_type'],$row['beneficiary']); 
            array_walk($lineData, 'filterData'); 
            $excelData .= implode("t", array_values($lineData)) . "n"; 
        } 
    }else{ 
        $excelData .= 'No records found...'. "n"; 
    } 

How to upload an image by binding directly to model properties in Livewire?

According to the official livewire docs we can bind data to the eloquent model’s properties directly like the following:

use AppPost;

class PostForm extends Component
{

    public Post $post;
    
    protected $rules = [
        'post.title' => 'required|string|min:6',
        'post.content' => 'required|string|max:500',
    ];

    public function save()
    {
        $this->validate();
 
        $this->post->save();
    }

}
<form wire:submit.prevent="save">
    <input type="text" wire:model="post.title">
 
    <textarea wire:model="post.content"></textarea>
 
    <button type="submit">Save</button>
</form>

But how can I upload an image and bind it to the model directly using the same approach?