사용자가 빈 사진 태그 대신 기본 이미지를 원하는 사진을 추가하지 않기로 선택하면 프로필 사진을 계정에 업로드 할 수있는 웹 기반 데이터베이스를 구축 중입니다. 어떤 이유에서든 파일이 선택되지 않으면, MySQL의 BLOB가 어쨌든 채워집니다. 무엇을 모르겠습니다. 추가 할 필요가있는 데이터베이스 나 코드 조각 내에서 변경할 필요가있는 것이 있습니까 ?? 데이터에 입력하기위한파일 업로드 - PHP MySQL
코드 : 표시 데이터
$username = mysql_prep($_POST["username"]);
$password = password_encrypt($_POST["password"]);
// $confirm = password_encrypt($_POST["confirm"]);
$firstName = mysql_prep($_POST["firstName"]);
$lastName = mysql_prep($_POST["lastName"]);
$File = $_FILES['fileField']['name'];
$tempnum = rand(20, 980780980);
$newfile = $tempnum . $File;
// if("password" != "confirm") {
// $_SESSION["message"] = "ERROR: Passwords must match.";
// }else{
if (file_exists("images/profile_pictures/" . $newfile)) {
echo $newfile . " already exists. ";
} else {
$query = "INSERT INTO users (";
$query .= " username, password, firstName, lastName, image";
$query .= ") VALUES (";
$query .= " '{$username}', '{$password}', '{$firstName}', '{$lastName}', '{$newfile}'";
$query .= ")";
$result = mysqli_query($connection, $query);
copy($_FILES['fileField']['tmp_name'], 'images/profile_pictures/' . $newfile);
if ($result > 0) {
// Success
$_SESSION["message"] = "User created.";
redirect_to("add_user.php");
} else {
// Failure
$_SESSION["message"] = "User creation failed.";
}
}
}
// }
}
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="add_user.php">
<h2>Create New User</h2>
<p>
<label for="fname">First Name:</label>
<input id="fname" type="text" class="textbox" name="firstName" value="" />
</p>
<p>
<label for="lname">Last Name:</label>
<input id="lname" type="text" class="textbox" name="lastName" value="" />
</p>
<p>
<label for="uname">Username:</label>
<input id="uname" type="text" class="textbox" name="username" value="" />
</p>
<p>
<label for="pword">Password:</label>
<input id="pword" type="password" class="textbox" name="password" value="" />
</p>
<p>
<label for="pword">Confirm Password:</label>
<input id="pword" type="password" class="textbox" name="confirm" value="" />
</p>
<!-- <p>-->
<!-- <label for="profile">Profile Picture:-->
<!-- <input id="fileField" type="file" name="fileField"></label>-->
<!-- </p>-->
<input type="submit" class="button" name="submit" value="Add User" onclick="return confirm('Do you wish to add a new user?');"/>
<p><a href="manage_users.php" class="link">Cancel</a></p>
</form>
</div>
코드 :
<table id="users">
<tr>
<th style="text-align: left; width: 75px;">Image</th>
<th style="text-align: left; width: 150px;">First Name</th>
<th style="text-align: left; width: 150px;">Last Name</th>
<th style="text-align: left; width: 150px;">Username</th>
<th style="text-align: left; width: 35px;">Actions</th>
</tr>
<?php while($user = mysqli_fetch_assoc($user_set)) { ?>
<tr>
<td>
<?php
if($user["image"] == ""){
echo "<img id='profilepic' src='images/profile_pictures/default.gif' alt='Default Profile Pic'>";
} else{
echo "<img id='profilepic' src='images/profile_pictures/".$user['image']."' />";
}?>
</td>
<!--htmlentities converts all applicable characters to html entities-->
<td><?php echo htmlentities($user["firstName"]); ?></td>
<td><?php echo htmlentities($user["lastName"]); ?></td>
<td><?php echo htmlentities($user["username"]); ?></td>
<td style="text-align: center;"><a href="edit_users.php?id=<?php echo urlencode($user["userId"]); ?>">
<img id="icon" src="images/edit.png" alt="Edit Icon"></a>
<a href="delete_user.php?id=<?php echo urlencode($user["userId"]); ?>" onclick="return confirm('Are you sure?');">
<img id="icon" src="images/delete.png" alt="Delete Icon"></a></td>
</tr>
<?php } ?>
</table>
당신은 이미지의 위치 대신에 데이터베이스의 이미지 자체를 저장할 수 있습니다
이 시도해보십시오. 이론적으로 이미지가 업로드되었는지 확인하십시오. 셀에 기본 사진의 위치를 저장하지 않은 경우 – CAO