Jump to content
php.lv forumi

Bildes no MySQL uz ekrana !


Aiko_Saule

Recommended Posts

Nu tā man ir datubaze ar nosaukumu aiko un tajā tabula Upload

struktūra sekojoša

 

Id tinyint(11) UNSIGNED auto_increment

name varchar(255)

size varchar(255)

type varchar(255)

content mediumblob BINARY

 

Es dabuju bmp failu datubazee bet nevaru dabuut ara

- ar ara es domaju izvadiit uz ekrana.

 

 

Man ir šads fails UploadXX3.php

 

<html>

<head>

<title>Download File From MySQL</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

 

<body>

<?php

// -------------------------- maina bufera vetribu ---------------------------------

 

$hostname="localhost";

$username="yyyyyyyy";

$password="xxxxxxx";

$dbName="aiko";

$usertable="Upload";

 

// ------------------------pievienojas datubazei--------------------------------------

MYSQL_CONNECT ($hostname,$username,$password) OR DIE ("nav servera");

mysql_select_db("$dbName") or DIE ("Nav DB");

 

$query = "SELECT id, name FROM Upload";

$result = mysql_query($query) or die('Error, query failed');

if(mysql_num_rows($result) == 0)

{

echo "Database is empty <br>";

}

else

{

while(list($id, $name) = mysql_fetch_array($result))

{

?>

<a href="UploadXX3.php?id=<?=$id;?>"><?=$name;?></a> <br>

<?

}

}

 

mysql_close();

?>

 

</body>

</html>

 

varu izvadiit faila nosaukumu bet failu ka bildi nevaru.

Link to comment
Share on other sites

varbūt tad selektē to bildi nevis viņas nosaukumu?

un lai izvadītu bildi tev vajadzēs padot pareizos headerus pirms tam.

 

labāk dari tā, ka iekš DB turi tikai faila nosaukumu, bet bildi liec vienkārši kā failu, un tad ar <img src .... /> parādīsi bildi.

Link to comment
Share on other sites

varu izvadiit faila nosaukumu bet failu ka bildi nevaru.

 

Protems, ka nevarfi izvadiit bildi, jo standartasituacijas html ir vien scripts, bet prieksh bildes ir otrs scripts.

Johtml nesatur sevii bildes datus, tikai noradi nrowserism no kadas vietas njemama pati bilde.

Link to comment
Share on other sites

Ir jaizvada ari faila headeri!

 

<img src="blabla.php?imgID=<?php echo $id; ?>" alt="image"/>

 

un blabla.php saturs :

<?php
header("Content-type: image/bmp");
//piesledzas DB;
$q = mysql_query("SELECT content FROM Upload WHERE id=".intval($_GET['imgID'])."");
$r = mysql_fetch_row($q);
echo $r[0];
?>

 

Nu kaut kaa taa.. domu cerams vismaz saprati.

Link to comment
Share on other sites

×
×
  • Create New...