<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c" -->

---
title: Workaround for PHP file_exists on ZIP file contents
description: PHP's file_exists() function fails to detect files inside a ZIP archive when using the zip:// stream wrapper syntax, even though file_get_contents() works...
canonical: https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Workaround for PHP file_exists on ZIP file contents | daily.dev
og:description: PHP's file_exists() function fails to detect files inside a ZIP archive when using the zip:// stream wrapper syntax, even though file_get_contents() works...
og:url: https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c
og:image: https://api.daily.dev/og/posts/e03uRXk8C.png
og:image:alt: Workaround for PHP file_exists on ZIP file contents
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Workaround for PHP file_exists on ZIP file contents

**[Maarten Balliauw](https://daily.dev/sources/maartenballiauw)** · 1 min read · 0 upvotes · 0 comments

## Summary

PHP's file_exists() function fails to detect files inside a ZIP archive when using the zip:// stream wrapper syntax, even though file_get_contents() works correctly on the same path. A workaround is provided: a custom zipped_file_exists() function that uses fopen() to attempt opening the file and checks whether the file handle is valid, instead of relying on file_exists().

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://blog.maartenballiauw.be/posts/2007-04-12-workaround-for-php-file_exists-on-zip-file-contents>

## Questions this post answers

### Why does file_exists() return false for a file inside a ZIP archive in PHP when using the zip:// stream wrapper?

file_exists() incorrectly returns false when checking a path like zip://some_file.zip#readme.txt, even though the file genuinely exists inside the archive and file_get_contents() on the same path successfully retrieves its data. The exact cause is unclear, but a workaround is to use fopen() instead: open the path in read mode and check whether the returned file handle is not false.

_Developers debugging quirky PHP stream wrapper behavior can compare notes and fixes on daily.dev._

## Similar posts on daily.dev

- [I Exist](https://daily.dev/posts/i-exist-8f1gyicqp) · The Daily WTF · 0 upvotes · 0 comments
- [File Upload Security in PHP and Laravel — The File That Isn’t What It Claims to Be](https://daily.dev/posts/file-upload-security-in-php-and-laravel-the-file-that-isn-t-what-it-claims-to-be-wcuzhbldv) · Medium · 1 upvotes · 0 comments
- [Coding Standard Proposal: Make it explicit that PHP files must use the .php extension](https://daily.dev/posts/coding-standard-proposal-make-it-explicit-that-php-files-must-use-the-php-extension-3r7bddkse) · Make WordPress Core · 11 upvotes · 4 comments

---

Tags: [#php](https://daily.dev/tags/php)

[View this post on daily.dev](https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Workaround for PHP file_exists on ZIP file contents","url":"https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c"},"datePublished":"2026-10-04T13:05:09.138Z","dateModified":"2026-10-04T13:09:05.014Z","description":"PHP's file_exists() function fails to detect files inside a ZIP archive when using the zip:// stream wrapper syntax, even though file_get_contents() works...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/01223f0ba7a3b297bffe9371601777bb?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/01223f0ba7a3b297bffe9371601777bb?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Maarten Balliauw","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Maarten Balliauw","logo":"https://media.daily.dev/image/upload/s--rOTg3VYO--/f_auto,q_auto/v1791119043/logos/maartenballiauw?_a=BAMAMicg0","url":"https://daily.dev/sources/maartenballiauw"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"php","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Maarten Balliauw","item":"https://daily.dev/sources/maartenballiauw"},{"@type":"ListItem","position":3,"name":"Workaround for PHP file_exists on ZIP file contents"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/workaround-for-php-file-exists-on-zip-file-contents-e03urxk8c#faq","mainEntity":[{"@type":"Question","name":"Why does file_exists() return false for a file inside a ZIP archive in PHP when using the zip:// stream wrapper?","acceptedAnswer":{"@type":"Answer","text":"file_exists() incorrectly returns false when checking a path like zip://some_file.zip#readme.txt, even though the file genuinely exists inside the archive and file_get_contents() on the same path successfully retrieves its data. The exact cause is unclear, but a workaround is to use fopen() instead: open the path in read mode and check whether the returned file handle is not false. Developers debugging quirky PHP stream wrapper behavior can compare notes and fixes on daily.dev."}}]}
```

