1
所以我有這個代碼。我正在上傳圖片,並希望在用戶上傳圖片後顯示圖片。請幫我用我的代碼,這裏只是一個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和這樣的顯示它我也希望它顯示在高度&寬度= 200像素;和邊界半徑:50%;
我相信你可以像這個例子一樣打印圖像:https://stackoverflow.com/questions/16284713/how-to-display-or-preview-a-uploaded-image-after-submitted-in-php- without-save-t –
[如何顯示或預覽上傳的圖像後提交的PHP沒有保存到數據庫?](https://stackoverflow.com/questions/16284713/how-to-display-or-preview -a上傳的圖像,之後提交的,在-PHP-沒有保存-T) –