删除功能和上传

时间:2012-11-13 22:56:49

标签: php mysqli

必须说我下载数据库并且所有功能都在课堂上。

这就是我令人难以置信的高兴功能并认为它们很好......

这就是我要如何构建一个图库,如果它与id_session匹配,则上传到网站的ID是登录页面,您可以选择删除它。所以它必须回到/最新的图片/从文件夹和数据库中删除它。但它会出现错误,你可以在这里看到;

致命错误:在第411行的/ home / jesperbo / public_html / mebe.dk / function / function.php中的非对象上调用成员函数bind_param()

这样我也正在建立一个上传系统的过程,其中底层数据库在我现在设置之后变得更小,当它完成时,2件事必须将我发送回/ latest-images /但它没有达到服务器上唯一可用的图片,并且与图片一起完成,但它根本不会以某种方式返回。所以到/ latest-images /

删除错误等等,我就在这里,

$stm1->bind_param('i', $id_gallery);

function img_slet_indhold(){
        if($_SESSION["logged_in"] = true && $_SESSION["rank"] == '1' || $_SESSION["rank"] == 2)
        {
            if($stmt = $this->mysqli->prepare('SELECT `title` FROM `gallery` WHERE `id_gallery` = ?'))
            {
                $stm1->bind_param('i', $id_gallery);
                $id_gallery = $_GET["id_gallery"];

                $stm1->execute();
                $stm1->store_result();
                $stm1->bind_result($title);

                $UploadDir = "/gallery/";
                //ligger i toppen af documentet, evt som en define

                if($stm1->fetch())
                {
                    $tmpfile = $UploadDir . "" . $title;
                    if(file_exists($tmpfile))
                    {
                        unlink($tmpfile);
                    }
                    $tmpfile = $UploadDir . "lille/" . $title;
                    if(file_exists($tmpfile))
                    {
                        unlink($tmpfile);
                    }
                    $tmpfile = $UploadDir . "store/" . $title;
                    if(file_exists($tmpfile))
                    {
                        unlink($tmpfile);
                    }
                }
                $stm1->close();
            }
            else
            {
                /* Der er opstået en fejl */
                echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
            }
        }


        if($stmt = $this->mysqli->prepare('DELETE FROM `gallery` WHERE `id_gallery` = ?' ))
        {
            $stmt->bind_param('i', $id);
            $id = $_GET["id_gallery"];

            $stmt->execute();

            header('Location: /nyeste-billeder/');

            $stmt->close();

        }
        else
        {
            /* Der er opstået en fejl */
            echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
        }
    }

因此,应该删除文件,我选择这样做;

<?php 
session_start();
require_once ("function/function.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);

$img_slet_indhold = $mebe->img_slet_indhold();

?>

所以当我将图片上传到文件夹和数据库时,上传后可以返回

function img_indhold(){
        if($_SESSION["logged_in"] = true && $_SESSION["rank"] == '1' || $_SESSION["rank"] == 2)
        {
            include "function/class.upload.php";
            $handle = new Upload($_FILES["filename"]);

            if($handle->uploaded)
            {
                //lidt mere store billeder
                $handle->image_resize = true;
                $handle->image_ratio_y = true;
                $handle->image_x = 220;
                $handle->Process("gallery/store");

                //til profil billede lign..
                $handle->image_resize = true;
                $handle->image_ratio_crop = true;
                $handle->image_y = 115;
                $handle->image_x = 100;
                $handle->Process("gallery");

                //til profil billede lign..
                $handle->image_resize = true;
                $handle->image_ratio_crop = true;
                $handle->image_y = 75;
                $handle->image_x = 75;
                $handle->Process("gallery/lille");
                $pb = $handle->file_dst_name;

            }
            if($stmt = $this->mysqli->prepare('INSERT INTO `gallery` (`title`, `id_bruger`) VALUES (?, ?)'))
            {

                $stmt->bind_param('si', $title, $id_bruger);
                $title = $pb;
                $id_bruger = $_SESSION["id"];

                $stmt->execute();

                header('Location: /nyeste-billeder/');

                $stmt->close();


            }
        }
     }

因此,当我需要在页面上调用它时,请执行此操作;

<?php 
session_start();
require_once ("function/function.php");
$mebe = new mebe;
$db = $mebe->db_c();
error_reporting(E_ERROR);

$img_slet_indhold = $mebe->img_slet_indhold();

?>

这是我何时上传到网站并在页面上显示图库/图片

function vise_img(){
        if ($stmt = $this->mysqli->prepare('SELECT `id_gallery`, `title`, `id_bruger` FROM `gallery` ORDER BY `gallery`.`id_gallery` DESC')) { 
            $stmt->execute();
            $stmt->store_result();
            $stmt->bind_result($id_gallery, $title, $id_bruger);

            while ($stmt->fetch()) {
                echo "<div id=\"gallery_box\">";
                echo "<a href=\"/profil/$id_bruger/\"><img src=\"/gallery/$title\" alt=\"\" height=\"115\" width=\"100\" border=\"0\"></a>";
                if($_SESSION["logged_in"])
                {
                    if($id_bruger == $_SESSION["id"])
                    {
                        echo "<ul>";
                        echo "<li><a href=\"/nyeste-billeder-slet/$id_gallery/\">Slet</a></li>";
                        echo "</ul>";
                    }
                }
                echo "</div>";
            }

            /* Luk statement */
            $stmt->close();

        } else {
            /* Der er opstået en fejl */
            echo 'Der opstod en fejl i erklæringen: ' . $mysqli->error;
        }
    }




   function upload_img(){
        if($_SESSION["logged_in"] = true && $_SESSION["rank"] == '1' || $_SESSION["rank"] == 2)
        {           
        ?>
        <form name="opslag" method="post" action="/nyeste-ok/" enctype="multipart/form-data">
            <input type="file" name="filename" id="filename" onchange="checkFileExt(this)">        
            <input name="upload" value="Upload" id="background_indhold" onclick="return check()" type="submit">
        </form>
        <?php
        }
        elseif ($_SESSION["logged_in"] != true && $_SESSION["rank"] != '1' || $_SESSION["rank"] != 2)
        {
            echo "<p>Du har ingen mulighed for at upload billeder på siden</p>";
        }

    }

真的希望你能够进一步帮助我!

1 个答案:

答案 0 :(得分:0)

我很难理解你的问题(我理解英语不是你的第一语言),所以我将基于你所包含的错误信息。在第一个函数img_slet_indhold()中,您的变量在if语句中被称为$stmt,但您将其称为$stm1;这似乎是导致错误的原因。