-1

重複の可能性:
データベースに保存されている繰り返し画像をTwitterのように背景に表示するにはどうすればよいですか?

Twitterと同じように(CSSリピートを使用して)背景に画像を表示したいのですが、問題は、MySqlデータベースから画像を取得していて、CSSが使用した背景のsrcタグを処理できないことです。次のコードとリンク

body{
    background:url(<?php $lastid=$_SESSION['lastid']; echo "get_test.php?id=$lastid";?>)     repeat;

   }

http://www.webdeveloper.com/forum/showthread.php?210964-Set-CSS-Background-Image-with-PHP

http://net.tutsplus.com/tutorials/php/supercharge-your-css-with-php-under-the-hood/

メインサイトの私のコード全体

<html>
<head>
<?php
$temp = tmpfile();
?>
<style>
  body{
    background:url(<?php $lastid=$_SESSION['lastid']; echo "get_test.php?id=$lastid"; ?>) repeat;

   }


</style>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
File:<br>
<input type="file" name="image">

<input type="submit" name="submit" value="Upload">

</form>



<?php

mysql_connect("host", "nam", "database") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$file= $_FILES['image']['tmp_name'];

$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = addslashes(getimagesize($_FILES['image']['tmp_name']));

if($image_size==FALSE)
{
echo "thats not an image";
}

else
{

mysql_query("INSERT INTO image_store VALUES ('','$image_name','$image')") or die(mysql_error());
 $lastid=mysql_insert_id();

$_SESSION['lastid']=$lastid;
 echo "the image is"."<image src=get_test.php?id=$lastid>";


}

?>
</body>

get_test.phpのコードは

<?php
mysql_connect("host", "nam", "database") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());


$id = addslashes($_REQUEST['id']);

$image=mysql_query("SELECT * FROM image_store WHERE id=$id ");
$image = mysql_fetch_assoc($image);
$image = $image['image'];

header("Content-Type: image/jpeg");
echo $image;

?>
4

2 に答える 2

0

$_SESSION変数を設定/使用するには(つまり$_SESSION['lastid']、各ページでセッションを開始する必要があります-

<?php
session_start();
?>
<html>
<head>
<?php
$temp = tmpfile();
?>
<style>
  body{
    background:url(<?php $lastid=$_SESSION['lastid']; echo "get_test.php?id=$lastid"; ?>) repeat;
   }
</style>
</head>
<body>
...
</body>
于 2013-01-01T20:24:37.480 に答える
0

これに答えるには:

1: 最後のセミコロンの後にスペースを追加します。これは以前に人々に問題を引き起こしました。

2: 背景の繰り返しを停止するには、background-repeatプロパティを使用してno-repeat、次のように に設定します。

background-repeat: no-repeat;
于 2013-01-01T18:49:42.843 に答える