/var/www/hkosl.com/b2b2c/webadmin/plupload/ajax_delete_image.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
    
include '../config.php';
    
// Check if the user is logged in

    
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) {
        
header("Location: ../login.php");
        exit;
    }

    
//delete file
    
if($_POST["clean_temp"] == 1){
        
//delete temp file in plupload/uploads which over 1 week
        //$time_ago = 1 * 24 * 60 * 60;

        /*$files = glob('uploads/*');
        foreach($files as $file) {
            $file_modifiy_time = filemtime($file);
            if($file_modifiy_time < (time() - $time_ago)){
                unlink($file);
            }
        }*/

        
$sql "select * from temp_file where deleted = ? and createdate <= ?";
        
$parameters = array("0"date("Y-m-d H:i:s"strtotime("-1 week")));
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
            exit;
        }

        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
            exit;
        }
        while(
$file_info $sth->fetch(PDO::FETCH_ASSOC)){
            if (!
unlink("uploads/".$file_info{"file_name"})){

            } else {
                
$sql2 "update temp_file set deleted = ? where file_id = ?";
                
$parameters2 = array("1"$file_info{"file_id"});
                if (!(
$sth2 $dbh->prepare($sql2))) {
                    throw new 
Exception('[' $sth2->errorCode() . ']: ' print_r($sth2->errorInfo()));
                    exit;
                }

                if (!
$sth2->execute($parameters2)) {
                    throw new 
Exception('[' $sth2->errorCode() . ']: ' print_r($sth2->errorInfo()));
                    exit;
                }
            }
        }

        echo (
"success");

    }else{
        
$file_id $_POST["file_id"];
        
$sql "select * from temp_file where file_id = ?";
        
$parameters = array($file_id);
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
            exit;
        }

        if (!
$sth->execute($parameters)) {
            throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
            exit;
        }
        
$file_info $sth->fetch(PDO::FETCH_ASSOC);

        if (!
unlink("uploads/".$file_info{"file_name"})){
            echo (
"fail");
        } else {
            echo (
"success");
        }
    }


?>