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 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。