我正在尝试将图像上传到数据库并将其保存在uploads / userimage中,以便可以在网站上显示图像。但我的问题是图像没有保存在我的目录中:uploads / userimage。
session_start();
include("functions/phpthumb/dbup.php");
$id = $_SESSION['werknemerid'];
// upload picture
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_SESSION['werknemerid'] != null){
if(!empty($_FILES["image"]["tmp_name"])) {
// set default variables
$image_folder = "../uploads/userimage";
$image_tmp = $_FILES["image"]["tmp_name"];
$image_ext = pathinfo($_FILES["image"]['name'], PATHINFO_EXTENSION);
$image_name = $_SESSION['voornaam']."".$_SESSION["tussenvoegsel"]."".$_SESSION['achternaam'].".".$image_ext;
// move the uploaded file
if(move_uploaded_file($image_tmp, $image_folder."/".$image_name)) // I think the problem is somewhere in this if statement
{
// load PHPThumb library
require_once("functions/phpthumb/ThumbLib.inc.php");
// create new thumbnail
$thumb = PhpThumbFactory::create($image_folder . "/" . $image_name);
$thumb->adaptiveResize(80,80);
$thumb->save($image_folder . "/" . $image_name);
}
$query = "UPDATE werknemer SET image = ? WHERE werknemerID = ?";
execSQL($query, array("si", $image_name, $id), true);
echo "<script>alert('Uw afbeelding is gewijzigd!');</script>";
echo "<meta http-equiv='refresh' content='0; url=mijnaccount' />";
}
}
}
// get image from database
if ($_SESSION['werknemerid'] != null){
$pagina_query = "SELECT image FROM werknemer WHERE werknemerID = ?";
$pagina_result = execSQL($pagina_query, array("i", $id), false);
$pagina_row = $pagina_result[0];
$_SESSION["image"] = $pagina_row[image];
}
我不知道我做错了什么...... :(
有人可以帮忙吗?
答案 0 :(得分:0)
也许您知道$ _FILES变量已设置为allready,但如果没有,请确保您拥有enctype =&#34; multipart / form-data&#34;在您的表单标签中。
启用错误报告。由于权限的原因,您无法保存文件的版面。
答案 1 :(得分:0)
这个问题的答案:
将文件夹和子文件夹的权限设置为777!