how to save image in mysql using php code

how to save picture of any person in our database using php as fronten

Page 1 of 1

6 Replies - 9288 Views - Last Post: 26 April 2010 - 12:30 PM Rate Topic: -----

#1 sapnashah_1310  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 10-January 10

how to save image in mysql using php code

Posted 11 January 2010 - 12:07 AM

pls
Is This A Good Question/Topic? 0
  • +

Replies To: how to save image in mysql using php code

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,000
  • Joined: 08-August 08

Re: how to save image in mysql using php code

Posted 11 January 2010 - 05:55 AM

Save the path to the image in the database, not the image. Saving the image will only slow things down.
Was This Post Helpful? 0
  • +
  • -

#3 OliveOyl3471  Icon User is offline

  • Everybody's crazy but me!
  • member icon

Reputation: 134
  • View blog
  • Posts: 6,581
  • Joined: 11-July 07

Re: how to save image in mysql using php code

Posted 11 January 2010 - 07:13 AM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

#4 it_1  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 15
  • Joined: 10-August 09

Re: how to save image in mysql using php code

Posted 13 January 2010 - 01:21 AM

you can save your image in database instead of saving the path in database.

first thing,

use longblob datatype in mysql table:

ex:

create table image_storing(filetype varchar(100),image longblob);

in the image column ur image has been saved.

php code:

first retrive the image path:

eg:
html code:
<form name="image_tr" action="form_save.php" enctype="multipart/form-data" method="post">
<input type="file" name="image_file" >
</form>


php code:in form_save.php
if($_FILES['image_file'][tmp_name]!="")
{
/* moving the image from tempdirectory to specified driectory*/
     move_uploaded_file($_FILES[''image_file'']['tmp_name'],"image/".$_FILES[''image_file'']['name']);

$image_type=$_FILES['image_file']['filetype'];
$image="image/".$_FILES[''image_file'']['name'];

/* image stroing in mysql */
$sql="insert into  image_storing values('$image_type','$image')";
$execute_sql=mysql_query($sql) or die("could not save");
if($execute_sql)
{
     unlink($image);/* to delete the image from folder*/
}
}


*** MOD EDIT: Added code tags. Please :code: ***
Was This Post Helpful? 0
  • +
  • -

#5 fresher123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-April 10

Re: how to save image in mysql using php code

Posted 26 April 2010 - 06:16 AM

I will try this code

This post has been edited by fresher123: 26 April 2010 - 06:17 AM

Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,000
  • Joined: 08-August 08

Re: how to save image in mysql using php code

Posted 26 April 2010 - 07:57 AM

View Postfresher123, on 26 April 2010 - 08:16 AM, said:

I will try this code
... and you will slow your system down. :splat:
Was This Post Helpful? 0
  • +
  • -

#7 jrm402  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 51
  • View blog
  • Posts: 333
  • Joined: 18-March 10

Re: how to save image in mysql using php code

Posted 26 April 2010 - 12:30 PM

You should never upload the image to the database. It will take up a lot of space and slow down your queries. What you should do, however, is follow the original set of instructions that were given to you by CTphpnwb.

Also when choosing an answer, that little green bar below the user picture with 'Reputation: *' in it is something to be noted. A high reputation signifies credibility. You should weigh their answers heavier.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1