| Autor | Zpráva | ||
|---|---|---|---|
| designed Profil * |
#1 · Zasláno: 10. 8. 2006, 10:38:09
Ahoj,
chtel bych poprosit o radu se skriptem php. Resim takovou situaci: potrebuji ukladat fotky do databaze MySQL. Ukladani mi funguje jak ma, ukladam do BLOB. Problem mam pri zobrazovani fotek z DB. Mam skript, kterym umim zobrazit fotky z pole BLOB, ale problem je v tom, ze se vechny nahledy zobrazuji se stejnym obsahem. Tzn. v DB mam napriklad tri fotky 1. hory, 2. jezero, 3. auto. Nyni mi skript zobrazi u nahledu vsech tri snimku napr. 3x hory nebo 3x jezero nebo 3x auto. Pokud kliknu na nahled tak se ale zobrazi velka fotka spravne. Takze problem je jen s nahledy. Spravne se ma zobrazit nahled 1x hory, 1x jezero, 1x auto. Diky za radu. Skripty: - strukrura tabulky - index.php - image.php CREATE TABLE image ( image_id int(10) unsigned NOT NULL auto_increment, image_type varchar(50) NOT NULL default '', image longblob NOT NULL, image_size bigint(20) NOT NULL default '0', image_name varchar(255) NOT NULL default '', image_date datetime NOT NULL default '0000-00-00 00:00:00', UNIQUE KEY image_id (image_id) ); index.php ------------- <?php $conn = mysql_connect("mysql", "jmeno", "heslo") OR DIE (mysql_error()); @mysql_select_db ("nazev_databaze", $conn) OR DIE (mysql_error()); if ($_FILES) { $image_types = Array ("image/bmp", "image/jpeg", "image/pjpeg", "image/gif", "image/x-png"); $userfile = addslashes (fread (fopen ($_FILES["userfile"]["tmp_name"], "r"), filesize ($_FILES["userfile"]["tmp_name"]))); $file_name = $_FILES["userfile"]["name"]; $file_size = $_FILES["userfile"]["size"]; $file_type = $_FILES["userfile"]["type"]; if (in_array (strtolower ($file_type), $image_types)) { $sql = "INSERT INTO image (image_type, image, image_size, image_name, image_date) "; $sql.= "VALUES ("; $sql.= "'{$file_type}', '{$userfile}', '{$file_size}', '{$file_name}', NOW())"; @mysql_query ($sql, $conn); Header("Location:".$_SERVER["PHP_SELF"]); exit(); } } if ($_GET) { $iid = $_GET["iid"]; $act = $_GET["act"]; switch ($act) { case rem: $sql = "DELETE FROM image WHERE image_id=$iid"; @mysql_query ($sql, $conn); Header("Location:./index.php"); exit(); break; default: print "<img src=\"image.php?iid=$iid\">"; break; } } ?> <html> <head> <title>Foto</title> </head> <body> <form method="post" enctype="multipart/form-data"> Select Image File: <input type="file" name="userfile" size="40"><input type="submit" value="submit"> </form> <?php $sql = "SELECT * FROM image ORDER BY image_date DESC"; $result = mysql_query ($sql, $conn); if (mysql_num_rows($result)>0) { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $i++; $str .= $i.". "; $str .= "<img src=\"image.php?iid=$iid\" width=\"100\" height=\"72\"> "; $str .= "<a href=\"index.php?iid=".$row["image_id"]."\">".$row["image_name"]."</a> "; $str .= "[".$row["image_date"]."] "; $str .= "[".$row["image_size"]."] "; $str .= "[<a href=\"index.php?act=rem&iid=".$row["image_id"]."\">Remove</a>]<br>"; } print $str; } ?> </body> </html> image.php ------------- <?php $conn = mysql_connect("mysql", "jmeno", "heslo") OR DIE (mysql_error()); @mysql_select_db ("nazev_databaze", $conn) OR DIE (mysql_error()); $sql = "SELECT * FROM image WHERE image_id=".$_GET["iid"]; $result = mysql_query ($sql, $conn); if (mysql_num_rows ($result)>0) { $row = @mysql_fetch_array ($result); $image_type = $row["image_type"]; $image = $row["image"]; Header ("Content-type: $image_type"); print $image; } ?> |
||
| WertriK Profil |
#2 · Zasláno: 10. 8. 2006, 12:25:31
Můj horký tip
$str .= "<img src=\"image.php?iid=$iid\" width=\"100\" height=\"72\"> "; nahradit tímto : $str .= "<img src=\"image.php?iid=".$row["image_id"]."\" width=\"100\" height=\"72\"> "; |
||
|
Časová prodleva: 20 let
|
|||
Toto téma je uzamčeno. Odpověď nelze zaslat.
0