Solved

Save PHP uploaded image and other files, MySQL tables or disk?

Posted on 2008-10-31
2
267 Views
Last Modified: 2012-05-05
I am trying to create a file attachment plug-in module for my script. It should be something similar to vBulletin Forum's attachment feature. I know MySQL team recommends to save files in a disk and only save the file name in the table, instead of saving the file itself within the BLOB field. But what I am trying to do is:

Content Type 1: My script has a public forum.
Content Type 2: My script has different kinds of memberships: Standard, Gold, Platinum
Content Type 3: My script will allow a user to send private message to another user.


If I am going to use BLOB field to save the file, I won't have any of the permission restriction problems because I can easily query the database to allow/deny user access, but if I am going to save the files to the disk, how can I:

1. For "Content Type 1", I want to only allow logged in user to be able to download a file or view a image? I don't want anybody to be able to download or view it by just using URL on their browser.

2. For "Content Type 2", how to restrict the file access to only certain type of members? Do I have to let the script to manipulate the .htaccess to allow/restrict the subdirectory? In this case  how should I do that with the .htaccess file? What if there are a lot of members that .htaccess will get too big and require too much server resource? Is it possible to use .htaccess + database combined method?

3. For "Content Type 3", this is a private content, so it should only be accessible by the receiver, but nobody else.

4. For these kind of permission to work, should I create a subdir for each and every user? I won't have any problem with this. But a user might have send several different kind of private content with attached files to different users, so they should be restricted by files, not by sender's private subdir as whole.

Hope this not too confusing, thank you.
0
Comment
Question by:santocki
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 22854649
You can use .htaccess or other file permission tools to restrict access to an image file directory.  

You can also set things up so the only file you would allow clients to see would be the index.php file.  The logic in the index.php file would control what other files they could see or not see.

The BIG disadvantage of putting a BLOB into a data base is that it will make the entire data base slow and hard to back up.  You will never again want to do a SELECT * if you have images in the data base.

A subdir for each client might make sense.  Or a file naming convention that used the client-id as a prefix to the file names.  If there are a lot of clients, the subdir collection is the best way to go.

Good luck, ~Ray
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question