【发布时间】:2014-01-31 16:08:34
【问题描述】:
我只是在尝试使用此 HTML 代码将图像上传到我的网络服务器的基本方法;
<form action="forgotten.php" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit">
</form>
这是我被遗忘的.php;
$response = array();
$text =""; /*create variable to save data */
$file = $_FILES['file'];
$name = $file['name'];
$path = "/uploads/" . basename($name);
if (isset($_POST['name'])) {
$name = $_POST['name'];
$file = $_POST['file'];
$description = $_POST['description'];
// include db connect class
require_once __DIR__ . 'http://www.buiud.com/android_connect/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = mysql_query("INSERT INTO products (path) VALUES ('" . mysqli_real_escape_string($path) . "')");
// check if row inserted or not
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
}
}
?>
而MySQL数据库包含两个Varchar路径和BLOB文件变量
php 文件没有显示任何错误或任何内容,它只是从未出现在数据库中。
我已将一个名为 uploads 的文件夹与两个脚本放在同一个文件夹中。
【问题讨论】:
-
显示数据库模式。此外,您正在混合
mysql_(已弃用)和MySQLi。而且您没有使用准备好的语句。 -
而且你永远不会在
$path中写任何东西。 -
让你
db_connect.php脚本世界(字面意思)可读,也不是一个好主意。 -
require_once __DIR__ . 'http://www.buiud.com/…'- 这是什么废话?将当前目录与 HTTP URL 连接是没有意义的,在这种情况下通过 HTTP 包含也没有意义。