Learning: The most efficient way to upload media and sort questionnaires in a db.
3 replies, posted
Okay,
So I have developed a personal framework for educational purposes - just because I have never really looked into things under the hood. I'm not trying to make anything impressive at all just trying to better my understanding of certain design patterns.
The question I have to any of you whom may have the experience, how would one go about handling uploading of media to a site via PHP where there could be multiple users. Would there be a specific hierarchy ie, alphabetical folders and sub-folders relative to the user or would you get a checksum of a users video that has been uploaded and store its name as such?
I'm not talking about merely uploading a video to a server via php i'm talking about a specific implementation of it which is efficient.
Anyway, the other question is. Suppose I want to make a questionnaire system where the user can create their own questions and answers ( already done that ) would you recommend saving the output as a JSON string and storing that JSON string in a single table in the db then decoding that string from the db when you want to fill out a test sheet?
Regards all,
1.) A lot of this depends on the amount of uploads. I prefer to store via relative paths, ie, files/user1/ and files/user2/ , but this can be expensive with a lot of files or a lot of users. With relatively few users and files, databases have enough overhead to add some cost and complexity, and the hashing itself is expensive with just a few users. You also need to worry about both filename collisions.
Small upload sites tend to use directories or a simple database system. Large upload sites (ie, dropbox) use hashing as it avoids duplicate data and is cheaper on space.
2.) Depends on how dynamic the form is. If it's always multiple choice questions with four answers, then don't bother with JSON, just store it in the db. If it's possible to have an infinite amount of answers, or you have 30 different forms, then use JSON (or serialize it). It's best to store some information (perhaps the questions and a UID) unencoded and only store the parts which can take dynamic forms (answers) encoded.
[QUOTE=blaze_r20;34329865]1.) A lot of this depends on the amount of uploads. I prefer to store via relative paths, ie, files/user1/ and files/user2/ , but this can be expensive with a lot of files or a lot of users. With relatively few users and files, databases have enough overhead to add some cost and complexity, and the hashing itself is expensive with just a few users. You also need to worry about both filename collisions.
Small upload sites tend to use directories or a simple database system. Large upload sites (ie, dropbox) use hashing as it avoids duplicate data and is cheaper on space.
2.) Depends on how dynamic the form is. If it's always multiple choice questions with four answers, then don't bother with JSON, just store it in the db. If it's possible to have an infinite amount of answers, or you have 30 different forms, then use JSON (or serialize it). It's best to store some information (perhaps the questions and a UID) unencoded and only store the parts which can take dynamic forms (answers) encoded.[/QUOTE]
Awesome insight, thanks blaze. I'll probably implement both methods for both and just test them out so I can really educate myself on it some more.
Thanks!
I'm not very experienced in this field but I do it this way:
1. User uploads the file.
2. PHP concatenates the filename, the date (possibly in the seconds from epoch format) and the first few bytes of the file and builds a md5 checksum of that.
3. The file itself is stored in a generic videos/ folder with the md5 checksum as its name. The original file name is kept in memory for later use.
4. PHP stores the data about the video in a database in a table structured this way:
[code]id (unique + auto inc.) - uploader user id - original file name (with extension) - md5 checksum - upload date (optional)[/code]
So the next time the video has to be fetched you'll know that if the user is looking for my_dog.mp4 you'll have to look through the table and see which md5 checksum the filename corresponds to, then you'll just load the file 'videos/<md5>.extension'.
That's just my two cents on how to do it.
[editline]22nd January 2012[/editline]
For the questions and answers system I'd use a table with all the questions (each with its unique id) and a table for the answer where every answer has its own id and also stores the id of the question it's related to and a flag to signal whether or not it's the correct answer. This would also allow questions with multiple correct answers.
Sorry, you need to Log In to post a reply to this thread.