将图像删除到目录和数据库(小管理区域)

时间:2015-01-07 12:03:47

标签: php database image directory

我有一个小脚本库,您可以从计算机的网络摄像头拍摄照片,这些照片保存在目录图像/和数据库中。

一切正常,但现在我想创建一个管理区域(当然我只关心功能),假设页面为admin.php和delete.php(包含该功能)。因此,我希望在所有图像的页面admin.php列表中显示,并且能够从简单的"删除"按钮。

不幸的是我曾多次尝试过,但我不是专家。

你需要什么来帮助我?

您粘贴几页:

的index.php

    <style type="text/css">
body{
    margin:0;
padding:0;
}
.img
    { background:#ffffff;
    padding:12px;
    border:1px solid #999999; }
.shiva{
 -moz-user-select: none;
    background: #2A49A5;
    border: 1px solid #082783;
    box-shadow: 0 1px #4C6BC7 inset;
    color: white;
    padding: 3px 5px;
    text-decoration: none;
    text-shadow: 0 -1px 0 #082783;
    font: 12px Verdana, sans-serif;}
</style>
<html>
<body style="background-color:#dfe3ee;">
<div id="outer" style="margin:0px; width:100%; height:90px;background-color:#3B5998;">
</div>
<div id="main" style="height:800px; width:100%">
<div id="content" style="float:left; width:500px; margin-left:50px; margin-top:20px;" align="center">
<script type="text/javascript" src="webcam.js"></script>
<script language="JavaScript">
        document.write( webcam.get_html(440, 240) );
</script>


<form>
<br />
        <input type=button value="Configure settings" onClick="webcam.configure()" class="shiva">
        &nbsp;&nbsp;
        <input type=button value="snap" onClick="take_snapshot()" class="shiva">
    </form>


</div>

<script  type="text/javascript">
    webcam.set_api_url( 'handleimage.php' );
        webcam.set_quality( 90 ); // JPEG quality (1 - 100)
        webcam.set_shutter_sound( true ); // play shutter click sound
        webcam.set_hook( 'onComplete', 'my_completion_handler' );

        function take_snapshot(){
            // take snapshot and upload to server
            document.getElementById('img').innerHTML = '<h1>Uploading...</h1>';

            webcam.snap();
        }

        function my_completion_handler(msg) {
            // extract URL out of PHP output
            if (msg.match(/(http\:\/\/\S+)/)) {
                // show JPEG image in page

                document.getElementById('img').innerHTML ='<h3>Upload Successfuly done</h3>'+msg;

                document.getElementById('img').innerHTML ="<img src="+msg+" class=\"img\">";

                // reset camera for another shot
                webcam.reset();
            }
            else {alert("Error occured we are trying to fix now: " + msg); }
        }
    </script>

<div id="img" style=" height:500px; width:500px; float:left; margin-left:40px; margin-top:20px;">
</div>
</div>
</body>
</html>

HANDLEIMAGE.php

<?php
session_start();
$_SESSION['id']="1";
$id=$_SESSION['id'];
include 'config.php';  //assume you have connected to database already.
$name = date('YmdHis');
$newname="images/".$name.".jpg";
$file = file_put_contents( $newname, file_get_contents('php://input') );
if (!$file) {
    print "Error occured here";
    exit();
}
else
{
    $sql="INSERT INTO image VALUES ('','$name','$newname')";
    $result=mysqli_query($con,$sql);
    $value=mysqli_insert_id($con);
    $_SESSION["myvalue"]=$value;

}
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . '/' . $newname;
print "$url\n";

?>

这些是主要页面,然后没有config.php文件和webcam.js和webcam.swf

1 个答案:

答案 0 :(得分:1)

您必须编写mysql删除查询以从数据库中删除图像路径,并使用unlink('文件路径')功能从文件夹中删除图像。

您需要重播其他任何帮助。