你也可以在GitHub(简单在线图书馆)中找到整个项目
哪个工作正常并且在mysql数据库中保存bookname bookauthor bookpages但它只是在数据库中保存图像名称和图像路径我只想将图像移动到名为images的新文件夹中并尝试几种方式,但它们都不适用于我。< / p>
答案 0 :(得分:1)
应修复如下
<?php
require_once("db.php");
$file = addslashes(file_get_contents($_FILES["images"]["tmp_name"]));
$sql = "INSERT INTO test1(name, lastname, age , images) VALUES('".$_POST["name"]."', '".$_POST["lastname"]."', '".$_POST["age"]."', '".$file."')";
if(mysqli_query($connect, $sql))
{
echo 'infos saved';
}
?>
<强>更新强>
您的AJAX脚本只发送文件名,而不是图像。正确的JS应该类似于下面的那个。
$.ajax({
url: "ajax_php_file.php", // Url to which the request is send
type: "POST", // Type of request to be send, called as method
data: new FormData(this), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
contentType: false, // The content type used when sending data to the server.
cache: false, // To unable request pages to be cached
processData:false, // To send DOMDocument or non processed data file it is set to false
success: function(data) // A function to be called if request succeeds
{
// do something ex. $('#loading').hide();
}
});