通过PHP上传OO配置文件图片
我使用面向对象技术开发了一个注册表,它运行良好,除非我尝试合并文件上载,以便用户可以将图片保存在数据库中 在我的数据库中,我使用BLOB格式并使用文件获取内容检索上传的文件 我以前有通过PHP上传OO配置文件图片,php,sql,Php,Sql,我使用面向对象技术开发了一个注册表,它运行良好,除非我尝试合并文件上载,以便用户可以将图片保存在数据库中 在我的数据库中,我使用BLOB格式并使用文件获取内容检索上传的文件 我以前有$profilepic=$\u POST['photo']这就是为什么$\u POST['photo']仍在第二个if语句中的原因 我有点困惑该使用什么格式,因为我没有做过很多面向对象的工作 提前谢谢 <center> <?php session_start(); include 'registra
$profilepic=$\u POST['photo']
这就是为什么$\u POST['photo']
仍在第二个if语句中的原因
我有点困惑该使用什么格式,因为我没有做过很多面向对象的工作
提前谢谢
<center>
<?php
session_start();
include 'registrationform.php';
include 'connection.php';
if (isset($_POST['regsubmit']))
{
$firstname = $_POST['firstname'];
$firstname = ucfirst($firstname);
$lastname = $_POST['lastname'];
$lastname = ucfirst($lastname);
$user = $_POST['username'];
$user = ucfirst($user);
$pass = $_POST['password'];
$spass = $_POST['secondpassword'];
$profilepic = file_get_contents($_FILES['photo']['tmp_name']);
if($_POST['firstname'] && $_POST['lastname'] && $_POST['photo'] && $_POST['username'] && $_POST['password'] && $_POST['secondpassword'])
{
if ($spass == $pass)
{
$query = "INSERT INTO users (firstname, lastname, photo, username, password) VALUES(?, ?, ?, ?, ?)";
$statement = $connection->prepare($query);
$statement->bind_param('ssbss', $firstname, $lastname, $profilepic, $user, $pass);
if($statement->execute()){
print 'Success!';
}else
{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}
else
{
print 'The passwords do not match!';
}
}
else
{
print 'Enter all fields please';
}
}
?>
</center>
您可以使用将上载的图像移动到文件夹中,并将图像名称存储在数据库中。
您可以按如下方式获取图像名称:
$image_name = $_FILES["photo"]["name"];
要显示图像,您可以检索图像名称。然后在html中可以显示如下图像:
有效的方法是使用move_uploaded_file()将图像文件移动到文件夹中,只需将图像名称存储在数据库中。请使用PHP来处理密码安全问题。如果您使用的PHP版本低于5.5,您可以使用密码\u hash()
。感谢这两个版本,现在就开始阅读它们。我该如何做这个Divyesh?得到以下答案?还是仍然困惑?谢谢你,伙计,分类:)