Top

[MYSQL] À̹ÌÁö,ÆÄÀÏ ¾÷·Îµå Çϱâ | Web-Programing
¾ÈÁöÈì (hoomiyam) | Editor | 2014/12/26 10:17:32 | Á¶È¸:61631

È£½ºÆà ¼­ºñ½º¸¦ ÀÌ¿ëÇϸ鼭 ÀúÀå°ø°£ÀÇ ºÎÁ·ÇÔÀ» ´À³¢°Ô µÌ´Ù. 

ƯÈ÷ À̹ÌÁöÆÄÀÏÀ» ¸¹ÀÌ ¾÷·Îµå ÇϰԵǴµ¥ ¿ë·®ÀÌ ¾Æ½±¿òÀ» ´À³¤´Ù. 

±×·¡¼­ ´ë¾ÈÀ» ã´ø Áß mysql ÀÚü¿¡ ÆÄÀÏÀÌ ¾÷·Îµå°¡ °¡´É ÇÏ´Ù°í ÇÏ¿© Å×½ºÆ® Çغ¸¾Ò´Ù.

 


1. Å×ÀÌºí »ý¼º



CREATE TABLE images(
id int NOT NULL auto_increment,
image mediumblob NOT NULL,
title varchar(100) DEFAULT NOT NULL,
width smallint(6) DEFAULT NOT NULL,  
height smallint(6) DEFAULT NOT NULL,
filesize int , # ÆÄÀÏÅ©±â
PRIMARY KEY (id)
) ;


* À§¿¡¼­ image Ä÷³¿¡ ÀÚ·áÇü¿¡ ´ëÇÑ °£´ÜÇÑ ¼³¸í
mysql ¿¡´Â ¹ÙÀ̳ʸ®¸¦ ÀúÀåÇÒ ¼ö ÀÖ´Â °ø°£ÀÎ blobÇüÀÌ Å©±âº°·Î 4°¡Áö°¡ ÀÖ´Ù.
tinyblob 255byte
blob 64KB
mediumblob 16MB
longblob 4G
·Î µÇ¾îÀÖ´Ù. ÇÏÁö¸¸ mysqlÀÇ ¹ÙÀ̳ʸ® ÀÔÃâ·Â 󸮴 DB¿¡ ±²ÀåÇÑ ¹«¸®¸¦ ÁֹǷΠmediumblob »ç¿ëÀ» ÃßõÇÑ´Ù.

 


 


2. Å×½ºÆ®¿ë ¼Ò¼Ò


 ÀÎÅÍ³Ý ¿©±âÀú±â ÀÖ´Â °Í ÁÖ¼­¼­ ¹Ù·Î °¡´ÉÇÏ°Ô ¼öÁ¤ÇÑ ¼Ò½º
µ¹¾Æ°¡°Ô¸¸ Çϱâ À§ÇÑ ¼Ò½º..

 


1) insert_img.php À̹ÌÁö ÀúÀå Æû

 

  1. <form action='image_up.php' method='POST' enctype='multipart/form-data'>
  2. < input TYPE=hidden name=mode value=insert>
  3. < table>
  4. < tr> <td>¿Ã¸± À̹ÌÁö:</td>
  5. < td><input type='file' name='image'></td></tr>
  6. < tr> <td>Á¦¸ñ</td>
  7. < td><input type='text' name='title'></td></tr>
  8. < tr> <td colspan = 2>
  9. < input type='submit' value='À̹ÌÁö Àü¼Û '></td></tr>
  10. < /table>
  11. < /form>


 


 2) image_up.php  À̹ÌÁö ÀúÀå ÈÄó¸®

  1. <?
  2. $connect=mysql_connect(  "localhost",  "¾ÆÀ̵ð",  "ºñ¹Ð¹øÈ£");
  3. mysql_select_db( "µðºñ¸í",$connect);
  4.  extract($_REQUEST);
  5.  $filename = $_FILES[image][tmp_name];
  6.  $handle = fopen($filename,"rb");
  7.  $size = GetImageSize($_FILES[image][tmp_name]);
  8.  $width = $size[0];
  9.  $height = $size[1];
  10.  $imageblob = addslashes(fread($handle, filesize($filename)));
  11. $filesize = $filename;
  12.  fclose($handle);
  13.  //¸Þ¸ð¸® ¿À·ù ¹æÁö
  14. ini_set("memory_limit" , -1);
  15.  $query="INSERT INTO  images (image,title,width,height) VALUES ('$imageblob', '$title', '$width','$height')" ;
  16.  $result=mysql_query($query,$connect );
  17.  echo "<script>location.href='images_list.php';</script>";
  18.  ?>


 

 


 3) images_list.php  À̹ÌÁö º¸ÀÌ´Â ¸®½ºÆ®

  1. <?
  2.  $connect=mysql_connect(  "localhost",  "¾ÆÀ̵ð",  "ºñ¹Ð¹øÈ£");
  3. mysql_select_db( "µðºñ¸í",$connect);
  4.  $query= "select id, title, width, height from  images order by id DESC " ;
  5.  $result=mysql_query($query,$connect );
  6.  $row=mysql_fetch_array($result);
  7.  echo "<a href=test.php>±×¸² ¿Ã¸®±â</a>";
  8.  echo( "<table bordr=1 width=90% align=center>
  9. < tr> <td>À̹ÌÁö</td>
  10.    <td>Á¦¸ñ</td>
  11. < /tr>
  12.  ");
  13.  while($row){
  14.      echo ( "<tr><td><a href=view.html?id=$row[id]><img src=./view.html?id=$row[id]
  15.  width=$row[width] height=$row[height] ></a></td>
  16. < td>$row[title]</td> ");
  17.    $row=mysql_fetch_array($result);
  18.    }
  19.    echo( "</table>");
  20.  ?>



 


 4) view.html    À̹ÌÁö º¸±â

  1. <?
  2.  $connect=mysql_connect(  "localhost",  "¾ÆÀ̵ð",  "ºñ¹Ð¹øÈ£");
  3. mysql_select_db( "µðºñ¸í",$connect);
  4.  extract($_REQUEST);
  5.  $query= "select * from images where id=$id" ;
  6.  $result=mysql_query($query,$connect );
  7.  $row=mysql_fetch_array($result);
  8.     Header(  "Content-type:  image/jpeg");
  9.     echo $row[image];
  10.   mysql_close();
  11.  ?>


À§¿¡ ó·³ Å×½ºÆ® Çغ¼ ¼ö ÀÖ´Ù.
ÇöÀç ³»°¡ »ç¿ëÇϴ ȣ½ºÆà ¾÷ü´Â cafe24 Àε¥ ¿©±ä mysql ¾÷·Îµå¸¦ 1MB·Î Çѵµ¸¦ Á¤ÇسõÀº °Í °°´Ù. 1MB ÀÌ»ó ¿Ã¸®¸é ½ÇÆа¡ µÈ´Ù.

 

±×·¡µµ ÀÌ°Ô ¾îµð¾ß!

 

 

°øÀ¯Çϱâ
°øÀ¯Çϱâ
2
0
0


´ñ±ÛÀ» ºÒ·¯¿À´Â ÁßÀÔ´Ï´Ù.
¡ã ÀÌÀü±Û [CSS] Å©·Ò¿¡¼­ textarea Å©±âÁ¶Àý ¾ÈµÇ°Ô ¸·±â ±è°æÈÆ (admin) 2014-12-31 13:49:55
¡å ´ÙÀ½±Û [PHP] ÇÁ·Î±×·¹½º¹Ù(BAR) ¸¸µé±â! ±è°æÈÆ (admin) 2014-11-14 18:56:19