我有一个仪表板,用户可以在其中登录并上传自己的个人资料图片,并将其保存到他们的个人资料中。这会将图像移动到正确的文件夹,并将其正确插入到数据库中。
直到最近我注意到图像消失时,它一直运行良好。在检查控制台中,我注意到404 not found图像出现错误,所以我检查了文件路径,图像不再存在(因此出现 404)。用户删除图像根本没有脚本,只能上传。
配置文件.php:
<p><b>Profile Picture: </b>
<?php
$picture = $row['imagePath'];
if (empty($picture)){
echo "<img src='profiles/no-image.png' width='100' height='100' >";
} else {
echo "<img src='profiles/".$row['imagePath']."' width='100' height='100' >";
};
?>
<form action="scripts/edit-picture.php" method="POST" enctype="multipart/form-data">
<input type="file" name="image"/>
<input type="submit" name="edit-picture" value="Upload"/>
</p>
</form>
edit-image.php 的脚本
<?php
require 'db.php';
session_start();
$uploadDir = '../profiles/';
// if edit-picture has been clicked on, run this if statement
if (isset($_POST['edit-picture'])) {
$studentID = $_SESSION['studentID'];
// Creating 4 different variables using the $_FILES global variable to get data about the image that
// you can view data about a file by doing: print_r($image);
$fileName = $_FILES['image']['name'];
$tmpName = $_FILES['image']['tmp_name'];
$fileSize = $_FILES['image']['size'];
$fileType = $_FILES['image']['type'];
$filePath = $uploadDir.$fileName;
// The below doesn't work as it assigns different value to folder and in db for image name
// $filePath = md5($file_name . microtime()) . substr($fileName , -5, 5);
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
header("Location: ../profile.php?img=errorFileRelocate");
exit;
}
// Checking file size - working
else if ($_FILES["image"]["size"] > 5000000) {
header("Location: ../profile.php?img=errorFileSizeError");
exit();
}
move_uploaded_file有没有人遇到过图像在通过任何帮助或指导移入文件夹后实际上从文件夹中消失的情况,我们将不胜感激。
呼如林