내가 도와 줄 수있어? 폴더에서 이미지를 검색하려고하는데 이미지가 표시되지 않습니다.php로 폴더에서 이미지를 표시하는 방법은 무엇입니까?
나는 "기사"테이블을 사용하고 있습니다 :
id int(100) auto increment,
title varchar(150),
imageName varchar(250) -> to store the file name,
image varchar(250) -> to store the image location address,
content text
가 여기 내 폴더 구조입니다 : 여기
내 코드의(artikel_created.php) -> 였는지를 기사의 제목, 이미지 및 내용
$tit = mysqli_real_escape_string($con, $_POST['title']);
$cont = mysqli_real_escape_string($con, $_POST['content']);
$fileName = $_FILES['image']['name']; //get the file name
$fileSize = $_FILES['image']['size']; //get the size
$fileError = $_FILES['image']['error']; //get the error when upload
$tmp = $_FILES['image']['tmp_name'];
?>
<?php include 'admin_header.php'; ?>
<body>
<section class="body">
<div id="log"></div>
<div id="artikel_created_panel">
<?php
if ($fileSize > 0 || $fileError == 0) {
$move = move_uploaded_file($tmp, '../assets/news_image/' . $fileName);
if ($move) {
$result = mysqli_query($con, "INSERT into articles(title, imageName, image, content) VALUES('$tit','$fileName','assets/news_image/$fileName', '$cont')");
if (!$result) {
trigger_error("Query Failed! SQL: $result - Error: " . mysqli_error($con), E_USER_ERROR);
} else {
echo "<br/>";
echo "Artikel added succesfully";
echo "<br/>";
}
}
}
?>
<a href=../admin/admin_panel.php>Back to admin panel</a>
</div>
</section>
여기 기사
if (isset($_GET['id'])) {
$id = $_GET['id'];
$qry = mysqli_query($con, "SELECT * FROM articles WHERE id=$id");
if (!$qry) {
trigger_error("Query Failed! SQL: $qry - Error: " . mysqli_error($con), E_USER_ERROR);
}
/*Fetching data from the field "title"*/
while ($row = mysqli_fetch_array($qry)) {
echo "<h2>" . $row['title'] . "</h2>";
echo "<img src=" . $row['image'] . " />";
echo "<p>" . $row['content'] . "</p>";
}
}
?>
다음
이미지의를 표시 (artikel.php)입니다 :
너희들이 코드를 잘못 제발 무엇을 말해 줄 수 있습니까?
'img' 요소에서 사용되는 결과 URL은 무엇입니까? 요청에 대한 서버의 응답은 무엇입니까? 파일이 실제로있는 곳입니까? – David
브라우저에서 열고 URL이 올바른지 확인하십시오. 또한 PHP에서 이미지를 동적으로 제공하는 경우 http 헤더의 mime-type 이미지를 확인해야합니다. – georoot
답변은 '/ assets/news_image/$ fileName'에 대한 sql 쿼리의'assets/news_image/$ fileName'' 변경입니다. ''그런 식으로 이미지를 깨고있는 절대 URL보다는 오히려 절대 URL을 사용하고있다. – georoot