È£½ºÆà ¼ºñ½º¸¦ ÀÌ¿ëÇÏ¸é¼ ÀúÀå°ø°£ÀÇ ºÎÁ·ÇÔÀ» ´À³¢°Ô µÌ´Ù.
ƯÈ÷ À̹ÌÁöÆÄÀÏÀ» ¸¹ÀÌ ¾÷·Îµå ÇϰԵǴµ¥ ¿ë·®ÀÌ ¾Æ½±¿òÀ» ´À³¤´Ù.
±×·¡¼ ´ë¾ÈÀ» ã´ø Áß 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 À̹ÌÁö ÀúÀå Æû
- <form action='image_up.php' method='POST' enctype='multipart/form-data'>
- < input TYPE=hidden name=mode value=insert>
- < table>
- < tr> <td>¿Ã¸± À̹ÌÁö:</td>
- < td><input type='file' name='image'></td></tr>
- < tr> <td>Á¦¸ñ</td>
- < td><input type='text' name='title'></td></tr>
- < tr> <td colspan = 2>
- < input type='submit' value='À̹ÌÁö Àü¼Û '></td></tr>
- < /table>
- < /form>
2) image_up.php À̹ÌÁö ÀúÀå ÈÄó¸®
- <?
- $connect=mysql_connect( "localhost", "¾ÆÀ̵ð", "ºñ¹Ð¹øÈ£");
- mysql_select_db( "µðºñ¸í",$connect);
-
- extract($_REQUEST);
-
- $filename = $_FILES[image][tmp_name];
- $handle = fopen($filename,"rb");
- $size = GetImageSize($_FILES[image][tmp_name]);
- $width = $size[0];
- $height = $size[1];
- $imageblob = addslashes(fread($handle, filesize($filename)));
- $filesize = $filename;
-
- fclose($handle);
-
- //¸Þ¸ð¸® ¿À·ù ¹æÁö
- ini_set("memory_limit" , -1);
- $query="INSERT INTO images (image,title,width,height) VALUES ('$imageblob', '$title', '$width','$height')" ;
- $result=mysql_query($query,$connect );
- echo "<script>location.href='images_list.php';</script>";
- ?>
3) images_list.php À̹ÌÁö º¸ÀÌ´Â ¸®½ºÆ®
- <?
- $connect=mysql_connect( "localhost", "¾ÆÀ̵ð", "ºñ¹Ð¹øÈ£");
- mysql_select_db( "µðºñ¸í",$connect);
-
- $query= "select id, title, width, height from images order by id DESC " ;
- $result=mysql_query($query,$connect );
- $row=mysql_fetch_array($result);
- echo "<a href=test.php>±×¸² ¿Ã¸®±â</a>";
- echo( "<table bordr=1 width=90% align=center>
- < tr> <td>À̹ÌÁö</td>
- <td>Á¦¸ñ</td>
- < /tr>
- ");
-
- while($row){
- echo ( "<tr><td><a href=view.html?id=$row[id]><img src=./view.html?id=$row[id]
- width=$row[width] height=$row[height] ></a></td>
- < td>$row[title]</td> ");
- $row=mysql_fetch_array($result);
- }
- echo( "</table>");
- ?>
4) view.html À̹ÌÁö º¸±â
- <?
- $connect=mysql_connect( "localhost", "¾ÆÀ̵ð", "ºñ¹Ð¹øÈ£");
- mysql_select_db( "µðºñ¸í",$connect);
-
- extract($_REQUEST);
- $query= "select * from images where id=$id" ;
- $result=mysql_query($query,$connect );
- $row=mysql_fetch_array($result);
-
- Header( "Content-type: image/jpeg");
- echo $row[image];
- mysql_close();
- ?>
À§¿¡ ó·³ Å×½ºÆ® Çغ¼ ¼ö ÀÖ´Ù. ÇöÀç ³»°¡ »ç¿ëÇϴ ȣ½ºÆà ¾÷ü´Â cafe24 Àε¥ ¿©±ä mysql ¾÷·Îµå¸¦ 1MB·Î Çѵµ¸¦ Á¤ÇسõÀº °Í °°´Ù. 1MB ÀÌ»ó ¿Ã¸®¸é ½ÇÆа¡ µÈ´Ù.
±×·¡µµ ÀÌ°Ô ¾îµð¾ß!
|