找到你要的答案

Q:files are not saved in folder after upload using PHP

Q:文件不会被保存在文件夹上传后使用PHP

I am trying to upload images to the database and save them in uploads/userimage so the images can be shown on the website. But my problem is that the image is not saved in my directory: 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];
}

I don't know what I am doing wrong... :(

Can someone please help?

我想上传图片到数据库并将它们保存在上传/ userimage所以图像可以显示在网站上。但我的问题是,图像没有保存在我的目录:上传/ 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];
}

我不知道我的问题出在哪里。:(

有人能帮忙吗?

answer1: 回答1:

Maybe you know the $_FILES variable is set allready, but if not, make sure you have the enctype="multipart/form-data" in your form tag.

Turn on error reporting. You'll get a arning of the file can not be save due to permissions.

也许你知道_files美元变量被设置了,但如果没有,请确保您有enctype =“multipart/form-data”表单中的标签。

打开错误报告。你会得到一个学习的文件无法保存由于权限。

answer2: 回答2:

The answer to this question:

Set permissions of the folder and subfolders to 777!

这个问题的答案:

设置权限的文件夹和子文件夹777!

php  image  upload