我想在数据库中插入图像路径。 在浏览器中,当任何用户选择图像路径时,该图像将存储在图像文件夹中,路径将存储在数据库中。 我试过但if($ type == ...)部分不起作用。它将转向else声明。
编辑:
if (isset($_POST['bSubmit'])) {
var_dump($_FILES);
$name = $_FILES['file']['name'];
$type=var_dump($_FILES['file']['type']);
if ($type == 'image/jpeg' || $type == 'image/png' || $type == 'image/gif') {
if (file_exists(dirname($_SERVER['DOCUMENT_ROOT']) . '/htdocs/Amit_404_Store/img/' . $name)) {
echo 'file is already present';
} else {
$uploadimage = move_uploaded_file($_FILES['file']['tmp_name'], dirname($_SERVER['DOCUMENT_ROOT']) . '/htdocs/Amit_404_Store/img/' . $name);
echo "Stored in: " . "" . $name . "<br />";
$destination = $name;
echo "Upload in: " . "" . $destination . "<br />";
//Database connection
$servername = "Localhost";
$username = "root";
$password = "";
$database = "new_404_store2";
//session value store and retrive data for index.html file
$email = $_SESSION['user_name1'];
$conn = mysqli_connect($servername, $username, $password, $database);
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$Update_query = "update customer_information2 set Image_Path='$destination' where Email_Id='$email'";
$result = mysqli_query($conn, $Update_query);
if (!$result) {
die('Could not enter data: ' . mysqli_error());
}
if ($uploadimage) {
echo 'image uploaded and stored';
} elseif (!$uploadimage) {
echo 'image not uploaded';
}
}
} else {
echo 'Invalid file type';
}
}
//mysqli_close($conn);
?>
答案 0 :(得分:0)
您尚未编写enctype,它是文件传输所必需的
$user = Auth::user();
// services will be lazy loaded on first access of the attribute
$services = $user->services;
dd($user->toArray());
答案 1 :(得分:0)
if ($type == 'image/jpeg' || $type == 'image/png' || $type == 'image/gif') {
应该是
if ($type == 'image/jpeg' || $type == 'image/jpg' || $type == 'image/png' || $type == 'image/gif') {
如果你正在添加图像文件但仍然出现错误