Marco
Marco

Reputation: 37

Delete image into directory and database (Small admin area)

I have a small script base where you can take shots from the computer's webcam, which are saved in a directory images / and in the database.

Everything works, but now I would like to create an admin area (of course I care for the moment only the functionality), with a hypothetical page admin.php and delete.php (containing the function). I therefore want to appear on the page admin.php list of all the images and the ability to delete them from a simple "delete" button.

Unfortunately I tried several times, but I'm not an expert.

What do you need to help me?

You paste a few pages:

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";

?>

These are the main pages, then there is no config.php file and webcam.js and webcam.swf

Upvotes: 0

Views: 166

Answers (1)

Cms Coders
Cms Coders

Reputation: 41

You have to write the mysql delete query for the remove the image path from database and the use unlink('file path') funcation to remove the image from the folder.

You want any other help replay on this.

Upvotes: 1

Related Questions