Solved

PHP MySQL/Folder - Protected file system

Posted on 2014-02-21
3
803 Views
Last Modified: 2014-02-21
Hello Experts,

I need an advice.

I know that the best way to upload and save files in a website is to upload them to a folder and save the file and link information in the database. Is simple and cheap when come to web-hosts (disk space is cheaper than paying for big database).

But i need to upload and protect video files. The website i'm building for my client will have files as the product do sell so.. i can't leave them open to download.

What's the best approach? store the files inside a blob field in mysql right?
.htaccess will not be practical or possible for this i think..
Or maybe there is a good service for this kind of features i don't know?..

Thx in advanced
0
Comment
Question by:justaphase
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 39876488
store the files inside a blob field in mysql right?
Not necessarily

Store them outside the webroot and stream them with script

Your request would look something like

mydomain.com/?video=0c241b1f-ec3e-1031-bf66-32903d7ec359

The key links to a DB record that contains the path to the file

You do your validation and check the person has the right to access the file and then do something like this

// construct $filepath here
header('Content-type: video/mpeg');
header('Content-Length: '.filesize($path)); // provide file size
header("Expires: -1");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);

readfile($filepath);

Open in new window

More info here on how to construct streaming / download code
How to use the Apache x-sendfile module
http://www.jasny.net/articles/how-i-php-x-sendfile/

A sample file streaming script
http://www.devshed.com/c/a/PHP/Video-Streaming-PHP-Script-Tutorial/3/

A very comprehenisve file streaming script with range checking
http://stackoverflow.com/questions/157318/resumable-downloads-when-using-php-to-send-the-file
0
 
LVL 1

Author Closing Comment

by:justaphase
ID: 39876512
Thank you :)
0
 
LVL 52

Expert Comment

by:Julian Hansen
ID: 39876589
You are welcome - thanks for the points.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

912 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now