使用echo在我的页面中显示图像

时间:2013-07-30 06:51:03

标签: php image get

这是我将从中获取图像的页面代码(完美地工作)

<?php
    ob_start();
    session_start();
    include('connect.php');

    $id = $_GET['id'];
    $query = mysql_query("SELECT * FROM news WHERE id=$id");
    $row = mysql_fetch_assoc($query);

    header("Content-type: image/jpeg");
    echo $row['image'];
?>

这是我在

中获取图片的页面
<?php
    ob_start();
    session_start();
    include('includes/connect.php');
    include('includes/phpCodes.php');

    $id = $_GET['id'];

    function showNews() {
        $data = array( 'id' => $id );
        $base = "includes/getImage.php";
        $url = $base. "?" . "id=36";
        echo $url;
        echo '<img src=includes/getImage.php class="newsImage">';
        echo '<h1><p class="subjecTitle">هنا العنوان</p></h1>   
                 <div class="newsContent">
                    hihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihihi
             </div>
        ';
    }
?>

<!DOCTYPE html>
<html>
    <head>
        <title>عينٌ على الحقيقة</title>

        <meta charset="utf-8">

        <link rel="stylesheet" type="text/css" href="css/mainstyle.css">
        <link rel="stylesheet" type="text/css" href="css/showstyle.css">
        <script lang="javascript">
            function logout( myFrame ) {
                myFram.submit();
            }
        </script>
    </head>
    <body>
        <div class="wrapper">
            <?php headerCode(); ?>
            <div class="content" dir="rtl">
                <?php showNews(); ?>
            </div>
        </div>
    </body>
</html> 

我认为我错了,有人可以告诉我如何解决它?对不起我的英语不好

3 个答案:

答案 0 :(得分:1)

为你清理它:

echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';

100%是否有效(如果$ id参数当然具有值)。

更新以修复丢失的$ id var:

    <?php
        ob_start();
        session_start();
        include('includes/connect.php');
        include('includes/phpCodes.php');

        $id = $_GET['id'];

        function showNews(){
            $id = $_GET['id'];
            $base = "includes/getImage.php";
            $url = $base. "?" . "id=36";
            echo $url;
            echo '<img src="includes/getImage.php?id=' . $id . '" class="newsImage">';

            echo '
                <h1><p class="subjecTitle">??? ???????</p></h1> 
                <div class="newsContent"></div>
            ';
        }
    ?>

答案 1 :(得分:0)

更改:

echo ' <img src=includes/getImage.php class="newsImage">';

致:

echo ' <img src="includes/getImage.php?id='.$id.'" class="newsImage">';

请注意src",并确保includes/getImage.php返回图片路径

答案 2 :(得分:0)

为什么你使用两个不同的页面? 将两个代码放在单个页面中,只需执行此操作

 <img src=includes/<?php echo $row['image']; ?> class="newsImage">