A-AA+then

รบกวนดู Code ให้หน่อยสิครับ

979

    ผมอยากให้แสดงเป็นรูปภาพเลยอ่ะครับ ไม่อยากให้มันแสดงเป็น list ก่อน
    ปกติมันจะแสดงเป็ร list ก่อน แล้วให้คลิกที่ชื่อถึงจะแสดงรูภาพ 
    ต้องแก้ยังไงหรอครับ   Code ข้างล่างนี้เลยครับ
    
    
    <?php
    $db_host = 'localhost';// don't forget to change
    $db_user = 'root';
    $db_pwd = '1234';

    $database = 'durable';
    $table = 'durable_table';
    // use the same name as SQL table

    if (!mysql_connect($db_host, $db_user, $db_pwd))
        die("Can't connect to database");

    if (!mysql_select_db($database))
        die("Can't select database");

    // This function makes usage of
    // $_GET, $_POST, etc... variables
    // completly safe in SQL queries

    elseif (isset($_GET['show']))
    {
        $id = intval($_GET['show']);

        $result = mysql_query("SELECT ext, UNIX_TIMESTAMP(input), picture
                                 FROM {$table}
                                WHERE durable_num=$id LIMIT 1");

        if (mysql_num_rows($result) == 0)
            die('no image');

        list($ext, $image_time, $data) = mysql_fetch_row($result);

        $send_304 = false;
        if (php_sapi_name() == 'apache') {
           // if our web server is apache
           // we get check HTTP
           // If-Modified-Since header
           // and do not send image
           // if there is a cached version

            $ar = apache_request_headers();
            if (isset($ar['If-Modified-Since']) &&// If-Modified-Since should exists
                ($ar['If-Modified-Since'] != '') &&// not empty
                (strtotime($ar['If-Modified-Since']) >= $image_time))// and grater than
                $send_304 = true;                                    // image_time
        }

    
        if ($send_304)
        {
           // Sending 304 response to browser
           // "Browser, your cached version of image is OK
           // we're not sending anything new to you"
            header('Last-Modified: '.gmdate('D, d M Y H:i:s', $ts).' GMT', true, 304);

            exit();// bye-bye
        }

       // outputing Last-Modified header
        header('Last-Modified: '.gmdate('D, d M Y H:i:s', $image_time).' GMT',
                true, 200);

       // Set expiration time +1 year
       // We do not have any photo re-uploading
       // so, browser may cache this photo for quite a long time
        header('Expires: '.gmdate('D, d M Y H:i:s',  $image_time + 86400*365).' GMT',
                true, 200);

       // outputing HTTP headers
        header('Content-Length: '.strlen($data));
        header("Content-type: image/{$ext}");

       // outputing image
        echo $data;
        exit();
    }
    ?>
    <html><head>
    <title>Picture_Durable</title>
    </head>
    <body>
    <?php
    if (isset($msg))// this is special section for
                    // outputing message
    {
    ?>

    <p style="font-weight: bold;"><?=$msg?>
    <br>
    <a href="<?=$PHP_SELF?>">reload page</a>
    <!-- I've added reloading link, because
         refreshing POST queries is not good idea -->

    </p>
    <?php
    }
    ?>

    <form action="<?=$PHP_SELF?>" method="post">
    <!-- This form is used for image deletion -->

    <?php
    $result = mysql_query("SELECT durable_num, input, durable_name FROM {$table} ORDER BY durable_num ASC");
    if (mysql_num_rows($result) == 0)// table is empty
        echo '<ul><li>No images loaded</li></ul>';
    else
    {
        echo '<ul>';
        while(list($id, $image_time, $title) = mysql_fetch_row($result))
        {
           // outputing list
            echo "<a href='{$PHP_SELF}?show={$id}'>{$title}</a> &ndash; ";
      
     } 

    }
    ?>

1 ความคิดเห็น

    ก็แก้ตอนที่ echo output สิคะ ก็เปลี่ยนเป็น echo image แทนที่จะ echo $title

1
^