Saving file structure in PHP
What is the best way to store the file structure along with the files, for example from a Zip file? Currently, each file is a string in a MySQL database, but obviously no structure can be read from it. I want to avoid storing the binary. All files must be text. Each zip / file structure is private to the user who sent it.
My recommendation would be similar to that of Olafur Waage, although I would use a single table with indicator columns to denote the "type" of the record.
id - Primary Key
parent_id - FK to self (id)
type - enum('D', 'F')
name - varchar
content - BLOB (if you wanted to ever store the file contents).
This follows a hierarchical tree structure, which for MySQL you can find more information here: http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/
a source to share
Better contextually. But, taking it as face value, I would say that the best way to preserve the file structure would be in the file system. Unless you need to link records together with other records or otherwise query them, a relational database is not the best choice for arbitrary, hierarchical data. You can also use a hybrid solution where you store the index in the database, with the file and possibly some metadata, but store it on the file system.
a source to share