{"record":{"id":"18881a38c8a29d18","repo":"dompdf/dompdf","slug":"file-file-not-found","errorCode":null,"errorMessage":"File '$file' not found.","messagePattern":"File '\\$file' not found\\.","errorType":"exception","errorClass":"Dompdf\\Exception","httpStatus":null,"severity":"error","filePath":"src/Dompdf.php","lineNumber":376,"sourceCode":"        }\n\n        if ($protocol === \"file://\") {\n            $ext = strtolower(pathinfo($uri, PATHINFO_EXTENSION));\n            if (!in_array($ext, $this->allowedLocalFileExtensions)) {\n                throw new Exception(\"Permission denied on $file: The file extension is forbidden.\");\n            }\n        }\n\n        foreach ($allowed_protocols[$protocol][\"rules\"] as $rule) {\n            [$result, $message] = $rule($uri);\n            if (!$result) {\n                throw new Exception(\"Error loading $file: $message\");\n            }\n        }\n\n        [$contents, $http_response_header] = Helpers::getFileContent($uri, $this->options->getHttpContext());\n        if ($contents === null) {\n            throw new Exception(\"File '$file' not found.\");\n        }\n\n        // See http://the-stickman.com/web-development/php/getting-http-response-headers-when-using-file_get_contents/\n        if (isset($http_response_header)) {\n            foreach ($http_response_header as $_header) {\n                if (preg_match(\"@Content-Type:\\s*[\\w/]+;\\s*?charset=([^\\s]+)@i\", $_header, $matches)) {\n                    $encoding = strtoupper($matches[1]);\n                    break;\n                }\n            }\n        }\n\n        $this->restorePhpConfig();\n\n        $this->loadHtml($contents, $encoding);\n    }\n\n    /**","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/dompdf/dompdf/blob/b14267808b811db092f53830f81f4706f4917c79/src/Dompdf.php#L358-L394","documentation":"The URI passed the protocol whitelist and all rules, but the actual read failed: Helpers::getFileContent() returned null. That means the file does not exist or cannot be read — wrong path, missing file, HTTP 404/5xx, DNS failure, SSL problem, allow_url_fopen disabled for remote URLs, or OS-level permission denial. This is the generic 'content could not be loaded' endpoint of loadHtmlFile().","triggerScenarios":"$dompdf->loadHtmlFile('https://example.com/missing.html') (404); a local path that does not exist; allow_url_fopen = Off in php.ini while loading http(s) URLs; a self-signed certificate failing TLS verification; the web server user lacking read permission on the file.","commonSituations":"Passing remote URLs that redirect or require auth; environments disabling allow_url_fopen for security; typos in paths; race where the file is generated asynchronously and not yet present when rendering starts.","solutions":["Verify the source loads from the same environment first: curl the URL or is_readable/file_exists the path as the web-server user.","For remote documents, enable allow_url_fopen or fetch with cURL (handling auth/TLS/redirects) and pass the body to loadHtml().","Fix permissions on local files (read access for the PHP process user).","If the document is generated asynchronously, ensure it exists (or wait/retry) before rendering."],"exampleFix":"// before\n$dompdf->loadHtmlFile('https://internal.example/report'); // may 404 or need auth\n\n// after: fetch explicitly with your own HTTP client, then load the string\n$resp = $http->request('GET', 'https://internal.example/report');\nif ($resp->getStatusCode() !== 200) {\n    throw new RuntimeException('Report source unavailable: HTTP ' . $resp->getStatusCode());\n}\n$dompdf->loadHtml((string) $resp->getBody());","handlingStrategy":"validation","validationCode":"if (parse_url($file, PHP_URL_SCHEME) !== null) {\n    // remote: check reachability with your HTTP client first\n    $status = headRequest($file);\n    if ($status !== 200) {\n        throw new RuntimeException(\"HTML source returned HTTP $status: $file\");\n    }\n} elseif (!is_file($file) || !is_readable($file)) {\n    throw new RuntimeException(\"HTML source missing or unreadable: $file\");\n}\n$dompdf->loadHtmlFile($file);","typeGuard":null,"tryCatchPattern":"try {\n    $dompdf->loadHtmlFile($file);\n} catch (\\Dompdf\\Exception $e) {\n    if (strpos($e->getMessage(), 'not found') !== false) {\n        // distinguish local-missing vs remote failure for the user; do not blind-retry\n    }\n    throw $e;\n}","preventionTips":["Verify sources exist and are readable before rendering; fail with the resolved absolute path in the message.","Ensure allow_url_fopen is enabled or fetch remote documents with cURL and use loadHtml().","For async-generated files, gate rendering on file existence rather than catching later."],"tags":["file","network","http","io","loading"],"backgroundTag":"file-not-found","analyzedSha":"b14267808b811db092f53830f81f4706f4917c79","analyzedAt":"2026-08-21T03:01:11.111Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}