contempoinc
contempoinc

Reputation: 25

PHP Warning: file_put_contents() failed to open stream: Is a directory in

I've searched and searched, but can't find an example like I'm experiencing, everything works but just looking to get rid of all the warnings this bit is throwing in my logs:

$propertyData = $propertyDetail->data;
$displayAddress = $propertyData->display_address;

if ( $displayAddress != "" ) {
    file_put_contents( $this->tmpDirectory."/slugs/".sanitize_title( $displayAddress ), $propertyData->property_id );
}

The $displayAddress is being pulled from an API call, it returns and creates the necessary files based off it, screenshot:

https://share.getcloudapp.com/2Nuyklxd (working properly)

Yet my logs are full of these:

PHP Warning: file_put_contents(/kunder/qzgb_2535/contem_4144/public/wp-real-estate-7/elementor-three-demo/wp-content/cache/idx_temp/slugs/): failed to open stream: Is a directory in /kunder/qzgb_2535/contem_4144/public/wp-real-estate-7/elementor-three-demo/wp-content/plugins/ct-idx-pro/classes/IDX.php on line 390

I realize that states "failed to open stream: Is a directory" which leads me to believe there's an issue with using a variable for the filename, or am I missing something simple?

Any help or guidance is appreciated.

Upvotes: 0

Views: 1309

Answers (1)

contempoinc
contempoinc

Reputation: 25

For anyone interested, I fixed it by removing the sanatize_title() function which was working but file_put_contents() was not 100% liking the output, here's the updated:

$propertyData = $propertyDetail->data;
$displayAddress = $propertyData->display_address;

if ( $displayAddress != "") {
    $displayAddress = strtolower($displayAddress);
    $displayAddress = preg_replace("/[^a-z0-9_\s-]/", "", $displayAddress);
    $displayAddress = preg_replace("/[\s-]+/", " ", $displayAddress);
    $displayAddress = preg_replace("/[\s_]/", "-", $displayAddress);

    file_put_contents( $this->tmpDirectory . "/slugs/" . $displayAddress, $propertyData->property_id );
}

Upvotes: 1

Related Questions