7 Replies - 2750 Views - Last Post: 27 September 2011 - 04:44 AM Rate Topic: -----

#1 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

store image or url in the database+ php

Posted 26 September 2011 - 06:53 AM

HI,

I am writing a shopping cart. I was planning to store images in the data base and retrieve it.
But now, I heard that the better option is to store the path to images that are in the project folder.

Is there any reason behind that ? If yes, plz explain. if there any alternative option can be give , that is
highlt appreciated.


thx in advance,
Menuka
Is This A Good Question/Topic? 0
  • +

Replies To: store image or url in the database+ php

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3490
  • View blog
  • Posts: 10,058
  • Joined: 08-June 10

Re: store image or url in the database+ php

Posted 26 September 2011 - 07:15 AM

it depends on the case. there are cases where it is better to store images (mostly where data integrity is concerned) in the DB while other are better off using URLs (esp. for large size images).
Was This Post Helpful? 0
  • +
  • -

#3 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: store image or url in the database+ php

Posted 26 September 2011 - 08:17 AM

[url]http://www.dreamincode.net/forums/topic/76064-uploading-images-with-php/[/url]

Quote

There have been a lot of posts in the PHP forum regarding how to upload files to a server and put them into a database. A lot of people were trying to put the entire binary file into the database, which was the incorrect way to do things. This tutorial is an attempt to explain how to properly upload images to your website, and store their records in the database using PHP and MySQL.

This post has been edited by menukadevinda: 26 September 2011 - 08:18 AM

Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: store image or url in the database+ php

Posted 26 September 2011 - 08:18 AM

Think about it this way. The file-systems that manage the files on the hard drives are databases specifically designed to store large amounts of binary data, and they do it very efficiently. Relational databases, on the other hand, are designed to store clearly defined pieces of information, and they do that very efficiently, but they don't do so well with the large blocks of binary data. Some NoSQL databases may blur the line a bit, but they are still closer to a RDBMS than a file-system.

You already have a very efficient, easy to use database system that was meant to store files. Why not take advantage of that?

Also, web servers are designed to serve files of the file system. If you want to serve files from withing other database systems, you will have to write additional code to serve as an intermediary. It's usually just unnecessary additional complexity.
Was This Post Helpful? 3
  • +
  • -

#5 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: store image or url in the database+ php

Posted 26 September 2011 - 08:27 PM

you mean for large piece of data not suitable to store in database but in the working folder like images in a image folder which located in the working folder.

Am I correct?

thx in advance,
Menuka
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: store image or url in the database+ php

Posted 26 September 2011 - 10:18 PM

Yes, that sounds about right.
Was This Post Helpful? 0
  • +
  • -

#7 menukadevinda  Icon User is offline

  • D.I.C Regular

Reputation: -7
  • View blog
  • Posts: 470
  • Joined: 14-April 11

Re: store image or url in the database+ php

Posted 27 September 2011 - 04:23 AM

HI, I was trying to do above problem and in a example code I found this.
$image = $_FILES['image'];

$image['name'] = mysql_real_escape_string($image['name']);

problem is, it is clear we can pass data to image varibale but how do we passe $image['name'] to mysql_real_escape_string instead of $image variable.

can anybody explain this?
Was This Post Helpful? 0
  • +
  • -

#8 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3712
  • View blog
  • Posts: 5,964
  • Joined: 08-June 10

Re: store image or url in the database+ php

Posted 27 September 2011 - 04:44 AM

The $image variable there is a copy of the $_FILES['image'] array. And as such it has multiple values, which you access by doing $image['element'], where "element" is the name of the value you want to get/set.

So when you do:
$image['name'] = mysql_real_escape_string($image['name']);


you are ensuring that the $image['name'] value is safe to use in a MySQL query.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1