所以我有这个代码。我正在处理上传图片,我想让它在用户上传后显示。请帮我解决我的代码,这里只是一个PHP新手。 :(
connect.php
<?php
$servername = "localhost";
$user = "root";
$password = "12345";
$db = "demo";
$con = mysqli_connect($servername, $user, $password, $db);
if (!$con) {
die('Could not connect: ' .mysql_error());
}
?>
try.php here
<?php include 'connect.php'; ?>
<?php
if (isset($image)) {
$errors = array();
$imageName = $_FILES['photoUpload']['name'];
$imageSize = $_FILES['photoUpload']['size'];
$imageType = $_FILES['photoUpload']['type'];
$imageTmp = $_FILES['photoUpload']['tmp_name'];
$imageExt = strtolower(end(explode('.', $imageName)));
$expensions = array("jpeg", "jpg", "png");
if(in_array($imageExt, $expensions)===false) {
$errors[] = "Extensions not allowed. Only JPEG, JPG, PNG";
}
if($imageSize > 2097152) {
$errors[] = "File size must not exceed 2MB";
} else { print_r($errors); }
}
?>
<div class="col-md-4">
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="file" name="photoUpload"><br><br>
<input type="submit" name="submit" value="SUBMIT"/>
<ul>
<li>Sent File: <?php echo $imageName; ?></li>
<li>File Size: <?php echo $imageSize; ?></li>
</ul>
</form>
</div>
我知道我在这里缺少像使用echo等显示它的东西。我也想让它以高度和高度显示width = 200px;和border-radius:50%;
答案 0 :(得分:0)
您是否在数据库中保存了它的名称?
如果是,请尝试以下
$id = $_SESSION['id'];
$sql = "SELECT image FROM user WHERE `id` = $id";
$result = mysqli_query($conn, $sql);
while ($row = mysqli_fetch_array($result)) {
echo "<div id='img_div'>";
//img tag fetching from folder 'images' - change to match the file it was uploaded to
echo "<img src='images/".$row['image']."' style='width:30%; height:30%;'>";
echo "</div>";
}
您需要更改查询以适合您的代码,但这个想法应该让您朝着正确的方向前进。