1
데이터베이스와 작동하는 게시물 작성자를 만들고 싶지만 이미지 나 파일을 업로드 할 수 없습니다. 내 웹 페이지가 구체화 프레임 워크를 사용하고 있습니다. 이 코드는 대부분 중요한 부분으로 축소되었습니다. 여기이미지/파일 업로드가 materializecss 프레임 워크에서 작동하지 않습니다.
<form action="add-post.php" method="post" enctype="multipart/form-data">
으로
<form action="add-post.php" method="post">
에서
<?php
require_once 'include/Database.php';
require_once 'include/Sessions.php';
require_once 'include/Functions.php';
if (isset($_POST['addPostButton']) || isset($_FILES['image'])) {
$imageName = $_POST['image'];
$imageDirectory = 'uploads/' . basename($_FILES['image']['name']);
if (!move_uploaded_file($_FILES['image']['tmp_name'], $imageDirectory)) {
$_SESSION['ErrorMessage'] = 'File is invalid!';
} else {
global $ConnectingDB;
$stmt = $ConnectingDB->prepare("INSERT INTO posts(image) VALUES('$imageName')");
if ($stmt->execute()) {
$_SESSION['SuccessMessage'] = 'Post created';
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Admin Dashboard</title>
<link type="text/css" rel="stylesheet" href="css/materialize.css">
<link type="text/css" rel="stylesheet" href="css/styles.css">
</head>
<body>
<form action="add-post.php" method="post">
<div class="row">
<div class="file-field input-field">
<div class="btn green">
<span>File</span>
<input type="file" name="image">
</div>
<div class="file-path-wrapper">
<input type="text" class="file-path" placeholder="Choose an image">
</div>
</div>
</div>
</form>
</body>
</html>
이미지 나 파일을 업로드 할 수 없습니다 ....... db 또는 프론트 엔드를 의미합니까? – kranthi
데이터베이스에 업로드하고 싶습니다. –