У меня проблемы с отображением изображения в php. В первом файле у меня есть вход, который получает изображение. <input type="file" name="imageOrVideo" accept="video/*,image/*" multiple>
. Во втором файле php я хочу получить изображение и отобразить его. Я получаю файл, используя $imageOrVideo = $_POST['imageOrVideo'];
. Если я повторяю $ imageOrVideo, все, что я получаю, - это строка. Я пробовал использовать echo img echo "<img src=Image/".$imageOrVideo."/>";
и echo "<img src=".$imageOrVideo."/>";
, но ни один из них не работал. Я читал, что вы можете отображать только строки, поэтому, возможно, мне не следует использовать echo, а использовать какой-то другой метод для отображения изображения. Вот полный код, чтобы увидеть, где может быть проблема. Спасибо за любую помощь. Это первый файл.
<!DOCTYPE html>
<html>
<head>
<title>Create Recipe</title>
<link rel="stylesheet" type="text/css" href="../CSS/createRecipe.css">
</head>
<body>
<div class="topnav">
<a href="includes/logout.inc.php">Sign Out</a>
<a href="">My Recipes</a>
<a href="index.php">Home</a>
</div>
<form action="includes/createRecipe.inc.php" method="post">
<div class="leftSide">
<input type="file" name="imageOrVideo" accept="video/*,image/*" multiple><br><br>
<!--
<input type="file" name="imageOrVideo" accept="image/*" ><br><br>
-->
<div class="prepTimeCookTime">
<label>Prep Time</label><br><br>
<textarea type="" name="prepTime" class="prepTime"> </textarea><br>
<label>Cook Time</label><br><br>
<textarea type="" name="cookTime" class="cookTime"> </textarea><br>
</div>
<div class="readyTimeNumberOfServings">
<label></label>Ready Time<br><br>
<textarea type="" name="readyTime" class="readyTime"> </textarea><br>
<label>Number of Servings</label><br><br>
<textarea type="" name="numberOfServings" class="numberOfServings"> </textarea><br>
</div>
</div>
<div class="rightSide">
<label>Recipe Title</label><br><br>
<textarea type="" name="recipeTitle" class="recipeTitle"> </textarea><br>
<label>Description</label><br><br>
<textarea type="" name="description" class="description"> </textarea><br>
<label>Ingrediants</label><br><br>
<textarea type="" name="ingredients" class="ingredients" placeholder="Put each ingrediant on its own line."></textarea><br>
<label>Directions</label><br><br>
<textarea type="" name="directions" class="directions" placeholder="Put each step on its own line."></textarea><br>
<button type="submit" name="recipe-submit">Submit</button>
</div>
</form>
</body>
</html>
Вот второй файл.
<?php
if(isset($_POST['recipe-submit'])){
require 'dbh.inc.php';
session_start();
$imageOrVideo = $_POST['imageOrVideo'];
$uidUsers = $_SESSION['userUid'];
$prepTime = $_POST['prepTime'];
$cookTime = $_POST['cookTime'];
$readyTime = $_POST['readyTime'];
$numberOfServings = $_POST['numberOfServings'];
$recipeTitle = $_POST['recipeTitle'];
$description = $_POST['description'];
$ingredients = $_POST['ingredients'];
$directions = $_POST['directions'];
//echo "<img src='" . $_POST['imageOrVideo'] . "' alt='img'>";
//echo "<img src='/images/test/" . $_POST['imageOrVideo'] . "' alt='img'>";
//print $imageOrVideo;
//echo "<img src=".$imageOrVideo."/>";
//echo "<img src=Image/".$imageOrVideo."/>";
/*
$sql = "INSERT INTO recipes (videoOrImages, uidUsers, prepTime, cookTime, readyTime, numberOfServings, recipeTitle, description, ingredients, directions) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)){
header("Location: ../createRecipe.php?error=sqlError");
exit();
}
else{
mysqli_stmt_bind_param($stmt, "bsssssssss", $imageOrVideo, $uidUsers, $prepTime, $cookTime, $readyTime, $numberOfServings, $recipeTitle, $description, $ingredients, $directions);
mysqli_stmt_execute($stmt);
header("Location: ../index.php?signup=success");
exit();
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
*/
}
else{
header("Location: ../createRecipe.php");
exit();
}