0

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, thanks!

  • what do you get when you `var_dump(sanitize_title( $displayAddress ))` – meewog Jul 31 '20 at 14:47
  • 1
    Does this answer your question? [PHP - Failed to open stream : No such file or directory](https://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory) – IncredibleHat Jul 31 '20 at 14:48
  • @MehrdadDastgir This is the output https://share.getcloudapp.com/o0u84PWo so it is returning some as empty which is related to the warnings but I have the if(condition) in place? Maybe I'm checking the wrong value? – contempoinc Jul 31 '20 at 15:02

1 Answers1

1

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 );
}