所以今天我试图将照片从管理文件上传到用户文件。我发现的一件事是我的代码工作正常,但是有点不对,我不知道在哪里。当我成功上传图片时,图片没有出现。但它已成功上传。你能救我一下吗?
这是我用来上传图片的代码
<?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>
虽然这是我从数据库调用2个类别的类,这是&#39; Foto&#39;和&#39;视频&#39;。
<?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
}
?>
最后一个是输出应该出来的地方。
$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
}
?>
这是我尝试插入图片时发生的事情
答案 0 :(得分:0)
我认为存在许可问题。你能否告诉我们以下代码的输出。
$row=mysqli_fetch_array($res)
并检查您尝试上传的文件夹。