|
ȣ ̿ϸ鼭 ̴.
Ư ̹ ε ϰԵǴµ 뷮 ƽ .
ã 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 ̻ ø а ȴ.
̰ !
|