Php picture save in mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nickyf
Forum Newbie
Posts: 1
Joined: Wed Oct 11, 2006 2:47 pm

Php picture save in mysql

Post by nickyf »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I try to save picture in mysql, all informations are inserted in mysql just picture not ...

slika_data is medium blob 
slika_type is varchar

all other variables work ok ...

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <meta http-equiv="Content-Language" content="sl" /> 
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250" /> 
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script> 
   <script type="text/javascript"> 

function FCKeditor_OnComplete( editorInstance ) 
{ 
   editorInstance.Events.AttachEvent( 'OnBlur' , FCKeditor_OnBlur ) ; 
   editorInstance.Events.AttachEvent( 'OnFocus', FCKeditor_OnFocus ) ; 
} 

function FCKeditor_OnBlur( editorInstance ) 
{ 
   editorInstance.ToolbarSet.Collapse() ; 
} 

function FCKeditor_OnFocus( editorInstance ) 
{ 
   editorInstance.ToolbarSet.Expand() ; 
} 

   </script> 
</head> 
<body> 



<?php 



if ($submit) { 

  // process form 

  $db = mysql_connect("localhost", "test", "test"); 

  mysql_select_db("test",$db); 

$functFP = fopen( $_FILES['slika']['tmp_name'], "rb"); 

$strBinaryData = fread( $functFP, filesize($_FILES['slika']['tmp_name'] )); 

$strPictureData = addslashes( $strBinaryData ); 

$strPictureType = $_FILES['slika']['type']; 

  $sql = "INSERT INTO katalog (ime,zvrst,letnik,vrsta,trgatev,opis,specifikacije,slika_data,slika_type) VALUES 

('$ime','$zvrst','$letnik','$vrsta','$trgatev','$opis','$specifikacije','" . \\$strPictureData . "' , '" . $strPictureType . "')"; 

  $result = mysql_query($sql); 

  echo "Slika in Informacije so vnešene.\n"; 

} else{ 



  // display form 



  ?> 



  <form method="post" action="<?php echo $PHP_SELF?>"> 

  Ime vina:<input type="Text" name="ime"><br> 
  Zvrst:<input type="Text" name="zvrst"><br> 
  Letnik:<input type="Text" name="letnik"><br> 
  Vrsta vina:<input type="Text" name="vrsta"><br> 
  Trgatev:<input type="Text" name="trgatev"><br> 
  <input type="file" name="slika" /><br> 

  <script type="text/javascript"> 

   var oFCKeditor = new FCKeditor( 'opis' ) ; 
   oFCKeditor.BasePath   = '/FCKeditor/' ; 
   oFCKeditor.ToolbarSet   = 'Basic' ; 
   oFCKeditor.Value = 'Opis' ; 
   oFCKeditor.Create() ; 

   </script> 

   <script type="text/javascript"> 

   oFCKeditor = new FCKeditor( 'specifikacije' ) ; 
   oFCKeditor.BasePath   = '/FCKeditor/' ; 
   oFCKeditor.ToolbarSet   = 'Basic' ; 
   oFCKeditor.Value   = 'Specifikacije' ; 
   oFCKeditor.Create() ; 
   </script> 

  <input type="Submit" name="submit" value="Enter information"> 

  </form> 



  <?php 



} // end if 



?> 



</body> 



</html>


If you have better solution to do this is also ok ...

Thanks


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
itsmani1
Forum Regular
Posts: 791
Joined: Mon Sep 29, 2003 2:26 am
Location: Islamabad Pakistan
Contact:

Post by itsmani1 »

Do not save picture in database.


just save the link of the picture in database and upload picture it.
Post Reply