srushti_k's avatar

srushti_k was awarded Best Answer+1000 XP

5mos ago

On Windows, ZipArchive keeps a hidden file lock even after close(). So your ZIP + source files get deleted, but the folder stays stuck with ghost entries. rmdir() fails even though the directory looks empty.

	if ($uploadFileSpaces == 1) {

			$zip = null;
			gc_collect_cycles();
			usleep(200000); // 0.2 sec — Windows needs it
			clearstatcache(true);

			//Then delete files + remove directory.
}

This kills the file lock, removes ghost files, and lets rmdir() actually work.

srushti_k's avatar

srushti_k wrote a reply+100 XP

5mos ago

On Windows, ZipArchive keeps a hidden file lock even after close(). So your ZIP + source files get deleted, but the folder stays stuck with ghost entries. rmdir() fails even though the directory looks empty.

	if ($uploadFileSpaces == 1) {

			$zip = null;
			gc_collect_cycles();
			usleep(200000); // 0.2 sec — Windows needs it
			clearstatcache(true);

			//Then delete files + remove directory.
}

This kills the file lock, removes ghost files, and lets rmdir() actually work.

srushti_k's avatar

srushti_k started a new conversation+100 XP

5mos ago

Hey Laracasts community!

I'm running into a frustrating issue in my Laravel app where, after uploading multiple documents, creating a ZIP file, and uploading it to cloud storage (DigitalOcean Spaces), the cleanup process isn't fully working. Specifically:

The individual files get deleted. The ZIP file gets deleted. But the empty directory persists, even though scandir() claims files still exist (yet I can't see them in the file system). This leaves behind empty folders cluttering the server. I'm wondering if ZipArchive is somehow causing this (e.g., file locks or lingering references), but I suspect it's a logic error in my cleanup code. The code works for the most part, but the directory check fails.

Here's the relevant snippet from my familyHeadSave method (inside a loop for handling document uploads like Aadhaar, PAN, etc.). This is where the zipping and cleanup happens:

please help!!! thank you !