{"record":{"id":"7c371ad2a4911b1f","repo":"PHPOffice/PhpSpreadsheet","slug":"file-path-not-found","errorCode":null,"errorMessage":"File $path not found!","messagePattern":"File \\$path not found!","errorType":"exception","errorClass":"PhpOffice\\PhpSpreadsheet\\Exception","httpStatus":null,"severity":"error","filePath":"src/PhpSpreadsheet/Worksheet/Drawing.php","lineNumber":176,"sourceCode":"                    $put = @file_put_contents($filePath, $imageContents);\n                    if ($put !== false) {\n                        if ($this->isImage($filePath)) {\n                            $this->path = $path;\n                            $this->setSizesAndType($filePath);\n                        }\n                        unlink($filePath);\n                    }\n                }\n            }\n        } else {\n            $exists = @file_exists($path);\n            if ($exists !== false && $this->isImage($path)) {\n                $this->path = $path;\n                $this->setSizesAndType($path);\n            }\n        }\n        if ($this->path === '' && $verifyFile) {\n            throw new PhpSpreadsheetException(\"File $path not found!\");\n        }\n\n        if ($this->worksheet !== null) {\n            if ($this->path !== '') {\n                $this->worksheet->getCell($this->coordinates);\n            }\n        }\n\n        return $this;\n    }\n\n    private function isImage(string $path): bool\n    {\n        $mime = (string) @mime_content_type($path);\n        $retVal = false;\n        if (str_starts_with($mime, 'image/')) {\n            $retVal = true;\n        } elseif ($mime === 'application/octet-stream') {","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/PHPOffice/PhpSpreadsheet/blob/65b080eef4d9fd11a5796135ab145883e5c3d6a6/src/PhpSpreadsheet/Worksheet/Drawing.php#L158-L194","documentation":"For non-URL paths, setPath() (with the default $verifyFile = true) keeps the path only if @file_exists() passes and isImage() agrees; isImage() uses mime_content_type() (fileinfo extension) and requires a mime type starting with 'image/'. If the internal path stays empty the exception 'File ... not found!' is thrown — it covers missing files, unreadable paths, and files fileinfo cannot classify (including valid images when the fileinfo extension is not loaded).","triggerScenarios":"$drawing->setPath('/tmp/upload42.png') after the temp file was moved or deleted; a relative path resolved against a different cwd (web vs CLI); open_basedir restrictions making file_exists() fail silently; a PHP build without fileinfo so mime_content_type() returns false for every file.","commonSituations":"Attaching drawings after moving/unlinking uploads; Docker or alpine php-cli images missing ext-fileinfo; truncated or non-image uploads; passing a directory or a dangling symlink.","solutions":["Pre-check with an absolute path: $path = realpath($relative); is_file($path) && str_starts_with((string) mime_content_type($path), 'image/').","If fileinfo is missing, install/enable the extension (e.g. install-ext fileinfo in your Docker image) — isImage() depends on it.","Attach the drawing before the file is moved or unlinked; regenerate corrupted sources."],"exampleFix":"// before\n$drawing->setPath('uploads/logo.png'); // File uploads/logo.png not found!\n\n// after\n$path = realpath('uploads/logo.png');\nif ($path === false || !str_starts_with((string) @mime_content_type($path), 'image/')) {\n    throw new RuntimeException('drawing source missing or not recognized as an image');\n}\n$drawing->setPath($path);","handlingStrategy":"validation","validationCode":"$path = realpath($relativePath);\nif ($path === false || !is_file($path) || !str_starts_with((string) @mime_content_type($path), 'image/')) {\n    throw new InvalidArgumentException('drawing source missing or not recognized as an image');\n}\n$drawing->setPath($path);","typeGuard":"function isUsableDrawingFile(string $path): bool\n{\n    return is_file($path)\n        && str_starts_with((string) @mime_content_type($path), 'image/');\n}","tryCatchPattern":"try {\n    $drawing->setPath($path);\n} catch (PhpSpreadsheetException $e) {\n    // regenerate or re-upload the source file, then retry\n}","preventionTips":["Use absolute paths (realpath) — the cwd differs between web and CLI runtimes","Attach drawings before moving or unlinking uploaded temp files","isImage() relies on the fileinfo extension; without it even valid images are reported as not found"],"tags":["php","phpspreadsheet","file-not-found","path","fileinfo","upload"],"backgroundTag":"file-not-found","analyzedSha":"65b080eef4d9fd11a5796135ab145883e5c3d6a6","analyzedAt":"2026-08-17T05:40:41.646Z","schemaVersion":2},"datasetVersion":"2026-08-17T09:17:11.063Z"}