Adding Image,Audio,Video in Database

Some days ago when i was developing a photo gallery with Jquery.

i need to store image and restore it for display. i was thinking how can i do it. by goggling and my friend rana told me it can be done by two way. one is storing image in blob format in database. but there is a problem with this when image size is big or number of image is big the database is going to heavy. so this technique is less used. another way is    storing image in a folder and saving link in database and then use it. this one is better.

for uploading a image need a file browser.

after uploading we need to process the file it need some server side script like php for categorize the image .this code like this

$pic_name = $_FILES ['image']['name'] ;

// for Processing JPEG Type Image.

if($_FILES['image']['type'] == 'image/jpeg' || $_FILES['image']['type'] == 'image/pjpeg')

// do some thing

// for Processing PNG Type Image.

else if($_FILES['image']['type'] == 'image/png' || $_FILES['image']['type'] == 'image/x-png')

//do something else

//and for GIF type Image

else if($_FILES['image']['type'] == 'image/gif')

after then we can upload image by this code
$address ='/upload/image/'.$pic_name;
// $name is a picture name given by us and $address is where we want to upload the file

if(move_uploaded_file($_FILES ['image']['name'],$address))
the show success.

we can upload music file the same way. only change is

if($_FILES['music']['type'] == 'audio/x-mp3' || $_FILES['music']['type'] == 'audio/mpeg')
you can add other type if you needed.

for video file upload check with this

if($_FILES['video']['type'] == 'video/3gpp')

after uploading just save the file path to the database and retrive when need.
i hope this little thing might help you.

Advertisement

Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.