473,569 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing files on a database?

I wrote this script to display different files from a database and
properly display them by their respective MIME types. I have two
questions: the first is that it just so happens not to work, and I'm
just wondering if there are any discrepancies that I can't see that
maybe someone else can, and the second is what would be the benefits
and the drawbacks of storing different types of files in a database,
for example files like jpeg and gif images, flash files, and mpeg
videos?

Code:
<?php
error_reporting (E_ALL);
require 'config.php';
$id = $_GET['id'];
$dbTable = $_GET['tb'];
dbConnect();
$query = "SELECT content, mime_type FROM ".$dbTable. " WHERE id=".$id;
$result = mysql_query("$q uery")
or die("Invalid query: " . mysql_error());
$data = mysql_fetch_arr ay($result);
header("Content-type: ".stripslashes( $data['mime_type']));
echo stripslashes($d ata['content']);
dbDisconnect();
?>

Dec 10 '06 #1
3 1895

Lucky_Syringe wrote:
dbConnect();
are you passing any parameters?
or calling mysql_select_db ('my_db'); ?

Dec 11 '06 #2
BKDotCom wrote:
Lucky_Syringe wrote:
dbConnect();

are you passing any parameters?
or calling mysql_select_db ('my_db'); ?
Why yes, yes I am...

Dec 11 '06 #3
On 9 Dec 2006 20:52:37 -0800, "Lucky_Syri nge" <ke**********@g mail.comwrote:
>I wrote this script to display different files from a database and
properly display them by their respective MIME types. I have two
questions: the first is that it just so happens not to work,
In what way does it not work?
>and I'm
just wondering if there are any discrepancies that I can't see that
maybe someone else can,
See below.
>and the second is what would be the benefits
and the drawbacks of storing different types of files in a database,
for example files like jpeg and gif images, flash files, and mpeg
videos?
Putting it in the database means the data will be easier to keep consistent
with its own metadata, and reduces some of the worries about inconsistencies
introduced by failures between the commit of the database changes, and changes
to a filesystem (where you can't just do a rollback). It can make it easier to
back up, or at least easier to restore to a consistent point.

But it means you have a lot more data in your database, which some databases
may not be able to handle well. Your database may not have good large object
support (MySQL certainly doesn't - there's no API to stream the contents out,
so fetching a BLOB ends up with the whole file copied from place to place in
memory potentially several times). It's also much faster to serve files off the
filesystem (although this can be mitigated by having a disposable filesystem
cache of the files, but keeping the database copy as the master).

The method to choose depends on lots of factors.
>Code:
<?php
error_reportin g(E_ALL);
require 'config.php';
$id = $_GET['id'];
$dbTable = $_GET['tb'];
dbConnect();
$query = "SELECT content, mime_type FROM ".$dbTable. " WHERE id=".$id;
Potential for a SQL injection attack - use of user input without validation.
>$result = mysql_query("$q uery")
or die("Invalid query: " . mysql_error());
$data = mysql_fetch_arr ay($result);
header("Conten t-type: ".stripslashes( $data['mime_type']));
Why the stripslashes here?
>echo stripslashes($d ata['content']);
And particularly here - this is likely to corrupt the file.
>dbDisconnect() ;
?>
--
Andy Hassall :: an**@andyh.co.u k :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5880
by: Bola | last post by:
Is anyone know how I can store Word Docs and PDF's in database, and how I can make link for visitor to download these files
3
2937
by: Dave Smithz | last post by:
Hi There, Being quite new to MS-SQL I would like to ask if there is a general opinion of what approach should be taken to storing things like external documents and images in databases. Should the actual files be stored within the database, or instead should links to the files on a file server or something similar be stored instead. ...
5
2133
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing database since most of the sites information is all stored there. As well there would be only one place to worry about backing up. And if the...
6
3039
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a folder on the server and then in the database table that I INSERT the news article, I'll store the path of the uploaded image. To me this seems a...
6
7704
by: stenospamron | last post by:
Does anyone have any advice as to how to get JPG images into an OLE Object field? I have created a table that includes this data type, and allowed Access wizzard to generate a form. I wish to copy various images from the web (in my initial trials, I copied the files to my PC), and which generally seem to be JPG files. However, Access...
7
2764
by: C G | last post by:
Dear All, What's the best way to store jpgs in postgresql to use in a web page? I tried to use large objects, but how would you extract them from a table to be viewed in a web-page without having to write them to a scratch file somewhere first? Thanks
4
4630
by: IkBenHet | last post by:
Hello, I am working on an ASP.NET based website project. Without going into much detail; One of the function on this website will be the possibility to upload images via a ASP.NET form to the webserver. These images can then be shown on to webpages throughout the site. What would be the best way of storing these images? Just by saving...
9
2360
by: Adam J Knight | last post by:
Hi all, Just wondering whats everyones prefered method of storing images ? 1) File System 2) Database (SqlServer) (Seems to be easier, but has a performance hit) Appreciate some insight!!! Cheers,
6
3187
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to me like there were performance issues at the time. How about the different types? The MS docs I would expect Access to differentiate and handle...
0
7710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7625
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7692
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6313
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5244
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3677
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3666
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2128
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.