Error file_get_contents(): read of 8192 bytes failed with errno=21(错误FILE_GET_CONTENTS():读取8192字节失败,错误号=21)
本文介绍了错误FILE_GET_CONTENTS():读取8192字节失败,错误号=21的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个简单的脚本,它在每个子文件夹的每个文件中搜索给定的字符串。它运行得很好,直到我相信我的PHP更新了(我不太确定是不是因为这个原因)。代码如下:<?php
$limit = ini_get('memory_limit');
ini_set('memory_limit', -1);
ini_set('max_execution_time', 300);
function get_directory_content($directory){
global $search, $results;
$files = scandir($directory);
foreach ($files as $file) {
if ($file == "." || $file == "..") {
continue;
}
$is_file = false;
$path = realpath($directory . DIRECTORY_SEPARATOR . $file);
if (is_dir($path)) {
get_directory_content($path);
$is_file = true;
}
else{
$is_file = true;
}
if ($is_file) {
$content = file_get_contents($path);
}
if (stripos($content, $search) !== false) {
$obj = new stdClass();
$obj->dir = ($directory . DIRECTORY_SEPARATOR . "<b>".$file."</b>");
$obj->file_name = $file;
array_push($results, $obj);
}
}
}
if (isset($_GET["submit"])) {
$search = $_GET["search"];
$results = array();
get_directory_content(dirname(__FILE__));
}
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Main</h1>
<form method="GET">
<p>
<input name="search" autocomplete="off" placeholder="Enter query here">
</p>
<input type="submit" name="submit">
</form>
<?php foreach ($results as $result): ?>
<h1><?php echo $result->file_name; ?></h1>
<p><?php echo $result->dir; ?></p>
<?php endforeach; ?>
</body>
</html>
我收到的错误是:注意:FILE_GET_CONTENTS():读取8,192字节失败,错误号=21是/Users/nikolaynikolaev/Server/original_search.php中第29行的目录
有人知道该问题的潜在修复方法吗?
如果你能帮我解决问题,我将不胜感激。提前感谢!:)
推荐答案
通知消息清楚地说明了这一点,是一个目录。
注意:FILE_GET_CONTENTS():读取[...]失败的字节数,错误号=21是[...]中的目录
要修复此错误,只需检查路径
foreach ($paths as $path) {
if (!is_file($path))
continue;
// this path points to a file
}
这篇关于错误FILE_GET_CONTENTS():读取8192字节失败,错误号=21的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:错误FILE_GET_CONTENTS():读取8192字节失败,错误号


猜你喜欢
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01