尝试从php表单将图像上载到db中
我试图通过使用PHP$\u文件将图像从html表单上传到MYSQL DB enter代码中,但我不知道我做错了什么,我是PHP新手尝试从php表单将图像上载到db中,php,html,mysql,Php,Html,Mysql,我试图通过使用PHP$\u文件将图像从html表单上传到MYSQL DB enter代码中,但我不知道我做错了什么,我是PHP新手 <form action="upload.php" enctype="multipart/form-data"> Username: <input type="text" name="username" value=""><br> Password: <input type="password" name="
<form action="upload.php" enctype="multipart/form-data">
Username: <input type="text" name="username" value=""><br>
Password: <input type="password" name="password" value=""><br>
Saga Title: <input type="text" name="saga_title"><br>
Saga Description: <input type="text" name="saga_description"><br>
Saga image (Max 4MB): <input type="file" name="saga_image"><br>
<input type="submit" name="upload_saga" value="Upload Saga"><br>
Episode Title: <input type="text" name="episode_title"><br>
Episode Saga: <input type="text" name="episode_saga"><br>
Episode Publication Date: <input type="text" name="episode_publication"><br>
Episode Link: <input type="text" name="episode_link"><br>
<input type="submit" name="upload_episode" value="Upload Episode">
</form>
<?php
include('./database_connection.php');
$connection = openConnection();
if ($_GET['username'] != "" && $_GET['password'] != "") {
echo $_FILES['saga_image']['tmp_name'];;
$username = $_GET['username'];
$password = $_GET['password'];
if ($username == "user" && $password == "pwd") {
if ($_GET['upload_saga'] != "") {
$imagename = $_FILES['saga_image']['name'];
$imagetmp=addslashes (file_get_contents($_FILES['saga_image']['tmp_name']));
$query = 'INSERT INTO "saga" (title, description, image) VALUES ("' . $_GET['saga_title'] . '", "' . $_GET['saga_description'] . '", ' . $imagetmp . ')';
echo $query;
$result = $connection->query($query);
if ($result === TRUE) {
echo '<p>Fatto</p>';
}
}
closeConnection($connection);
?>
用户名:
密码:
传奇故事标题:
传奇故事描述:
传奇图像(最大4MB):
剧集标题:
插曲传奇:
插曲出版日期:
插曲链接:
好的,首先要读的是散列密码。您不能传递代码中未加密的密码。话虽如此,即使可以将图像文件的内容添加到数据库中的字段中,也不应该这样做。查阅参考资料。最后,有多种原因导致它可能无法按预期的方式工作,但您需要向我们展示您遇到的错误。首先,为什么要这样使用user和pssw?第二步,将文件移动到服务器,然后将链接保存到数据库,以便在出现问题时回拨。