PHP 警告:file_put_contents() 无法打开流:是

问题描述 投票:0回答:1

我搜索了又搜索,但找不到像我正在经历的例子,一切正常,但只是想摆脱这个位在我的日志中抛出的所有警告:

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

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

$displayAddress
正在从 API 调用中提取,它返回并基于它创建必要的文件,屏幕截图:

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

然而我的日志里充满了这些:

PHP警告:file_put_contents(/kunder/qzgb_2535/contem_4144/public/wp-real-estate-7/elementor- Three-demo/wp-content/cache/idx_temp/slugs/):无法打开流:是目录/kunder/qzgb_2535/contem_4144/public/wp-real-estate-7/elementor- Three-demo/wp-content/plugins/ct-idx-pro/classes/IDX.php 第 390 行

我意识到“无法打开流:是一个目录”这让我相信使用变量作为文件名存在问题,或者我错过了一些简单的东西?

感谢任何帮助或指导。

php warnings file-put-contents
1个回答
1
投票

对于任何感兴趣的人,我通过删除 sanatize_title() 函数来修复它,该函数正在工作,但 file_put_contents() 并不是 100% 喜欢输出,这里是更新的:

$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 );
}
© www.soinside.com 2019 - 2024. All rights reserved.