dongshi4589 2017-05-20 14:38
浏览 255
已采纳

成功上传后,图片不会显示

so today I was trying to upload photo from admin file to user file. One thing I discovered is that my code works fine, but something is a little bit wrong I don't know where. When I successfully uploaded the picture, the picture didn't appear. But it successfully been uploaded. Could you help me out?

This is the code I used to upload the picture

         <?php
          require_once ('db/database.php');

          if(isset($_POST['submit']))
          {
            $name = basename($_FILES['file_upload']['name']);
            $t_name = $_FILES['file_upload']['tmp_name'];
            $dir = 'fotovid';
            $kat = $_POST['kat'];
            if(move_uploaded_file($t_name, $dir."/".$name))
            {
              mysqli_select_db($koneksi, 'koneksi_oop');
              $query = "INSERT INTO gallery (id_gambar, kat_gambar, nama_gambar, path) VALUES ('', $kat, '$name', 'fotovid/$name')";
              $res = mysqli_query($koneksi, $query);
              echo "Berhasil upload foto";
            } else {
              echo "Gagal upload foto";
            }

          }
        ?>

        <div class="wrapper">

            <div class="panel"">

                <div align="center" style="padding-top: 100px;">        
                   <!--  <div class="container1" style="background-color: none;margin-bottom: 235px;">
                        <label for="file-input">Upload Video</label>
                            <input type="file" accept=".mp4,.mkv" id = "file-input" style="background-color: none; width: 300px; "><br/>
                            <script type="text/javascript" src = "assets/js/videoJS.js"></script>
                    </div> -->
                     <form action="inputfoto.php" method="post" enctype="multipart/form-data">
                    <input type="file" name="file_upload" /><br/>
                    <label>Kategori</label>
                    <input type="text" name="kat"><br/>
                    <input type="submit" name="submit" value="Upload">
                </form>  
                </div>

            </div>
        </div>

While this is the class where I call 2 categories from database, which is 'Foto' and 'Video'.

   <?php
    include ('admin/db/database.php');
        $query = "SELECT * FROM kategori_gambar";
        $res = mysqli_query($koneksi, $query);
        while ($row=mysqli_fetch_array($res)) 
        {
    ?>
        <div>
            <fieldset style="margin:0px 40px 100px 40px;">
                <legend>

                    <a href="keluar_gambar.php?kat_gambar=<?= $row['id'];?>">
                        <?php
                            echo $row['nama'];
                         ?>
                    </a>
                </legend>
            </fieldset>
        </div>
        <?php
            }
        ?>

And the last one is where the output should comes out.

                $query = "SELECT * FROM gallery WHERE kat_gambar =".$_GET['kat_gambar'];

                $res = mysqli_query($koneksi, $query);
            ?>

            <!DOCTYPE html>
            <html>
            <head>
                <title></title>
            </head>
            <body>
            <?php
                while($row=mysqli_fetch_array($res))
                {
            ?>
                <img src = "<?php echo $row['path']; ?>" width='300px' height= "200px" /><br/>
                <?php
                    }
                ?>

This is what happened when I tried to insert the image

enter image description here

enter image description here

enter image description here

enter image description here

  • 写回答

1条回答 默认 最新

  • dongmacuo1193 2017-05-20 16:17
    关注

    I think there is a permission issue. could you please show us the output of the following code.

    $row=mysqli_fetch_array($res)
    

    and also check the folder where you tried to upload.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败