abigsmurf Posted June 11, 2008 Share Posted June 11, 2008 I've been coding a file explorer system where you can select an individual file or a folder on a server and it'll add all these files to a zip and download them. The problem I'm having is that when you add a folder it can contain hundreds, possibly even in rare occasions, thousands of files in various sub folders. Currently I traverse the folders, add each file name to the end of a string. when the folder has been fully explored and every file added, this string is then passed to exec zip. This results the PHP using up far too much memory if it has to go through a large folder and it aborts partway through (works perfectly fine for medium numbers of files), it's not the size of the zip itself that's an issue, just the memory used by the code. I can't really ask the hosts to increase the memory allocation (I've no access to php.ini myself) so I need to find a way of adding folders to a zip that minimises memory usage. I've three possibilities in my mind but I need to know if they're possible, if they'll solve the problem and, probably most importantly, what the code is to do them. 1: adding each file name to a file and just passing that to zip so the memory isn't filled up. 2: simply just adding the folder as a whole to the zip at once without running any traversal scripts. (please say you can do this, by far the easiest solution) 3: adding each file individually to the same zip as the code runs through the files rather then waiting till the end and adding all at once. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/109768-out-of-memory-error-when-zipping-large-numbers-of-files/ Share on other sites More sharing options...
abigsmurf Posted June 11, 2008 Author Share Posted June 11, 2008 I've discovered the -r suffix will zip a folder. However will this replace an existing zip file or add to it? I need to be able to add multiple files and folders Link to comment https://forums.phpfreaks.com/topic/109768-out-of-memory-error-when-zipping-large-numbers-of-files/#findComment-563390 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.