uploads.php

File Type: php File Location: monofiles/ File name: uploads.php
<?php

    
include_once 'data_connect.php';
    
    if (isset(
$_GET['max'])) {
    
        
$settingsXML simplexml_load_file('filesinfo/settings.xml');
        
$lastmod $settingsXML->general->imgshow->lastmod;
            
            if ((isset(
$_GET['at'])) && ($_GET['at'] < (int)$lastmod)) {
                
                
header('Location:uploads.php');
                exit();
            }
    }

    if (isset(
$_POST['MAX_FILE_SIZE'])) {
    
    
$tname time();
    
    
$target_path '../images/'.basename$_FILES['uploaded']['name']);    
    
    if (
strpos('.png .jpg .gif',substr($target_path,-4)) !== false) { 
    
        
$directory = new DirectoryIterator('../images/');
    
        
        foreach (
$directory as $fileinfo) {
        
                
                if (
$fileinfo->isFile()) {
                    
                    
$name $fileinfo->getFilename();
                    
$xt $fileinfo->getExtension();
                    
                                    
                    if (
$name == basename$_FILES['uploaded']['name'])) {
                        
                        
$target_path '../images/'.$tname.'-'.basename$_FILES['uploaded']['name']);
                        break;
                    }
                        
                    
                }
                
        }        
        
        if (
move_uploaded_file($_FILES['uploaded']['tmp_name'], $target_path)) {
            
            
$_SESSION['imgupload'] = 'success';
            
            
header('Location:uploads.php');
            exit();
        }
        
        else {
        
        
$_SESSION['imgupload'] = 'error';
        
        
header('Location:uploads.php');
        exit();
        
        }
                    
        
    }
    

    else {
    
    
$_SESSION['imgupload'] = 'filesupport';
    
    
header('Location:uploads.php');
    exit();
    
    }

}


    if ( isset(
$_GET['delimg']) ){
        
        
$img $_GET['delimg'];
    
        if (
is_file($img)) {
            
            
unlink($img);
            
$message '<div id="action-confirm"><span>Image deleted</span></div>';
                        
    }
    
        
}

?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Images</title>
<link rel="stylesheet" type="text/css" href="cmstyle.css">
<?php include 'csstheme.php' ?>
<script type="text/javascript"> function conf(form){ return confirm('Delete file?'); }</script>
</head>
<body>
<?php
    
        
include 'mypanel.php';
            
        if (isset(
$_SESSION['imgupload'])) {
            
            
            if (
$_SESSION['imgupload'] == 'success')
            
            echo 
'<div id="action-confirm"><span>Image uploaded</span></div>';
            
            
            
            if (
$_SESSION['imgupload'] == 'error')
            
                echo 
'<div id="error-confirm"><span>Error uploading file</span></div>';
            
            
            
            if (
$_SESSION['imgupload'] == 'filesupport')
            
                echo 
'<div id="error-confirm"><span>File type is not supported. File extensions allowed: .gif, .jpg, .png</span></div>';
            
            
            unset (
$_SESSION['imgupload']);
        }
        
        
        if (isset(
$message))
        
            echo 
$message
    ?>
    <div class="main">
        <h1>Images</h1>
        <div id="main-container">
            <div style="height:30px"></div>
            
            <!-- FORM -->
             <form id="imgform" enctype="multipart/form-data" action="uploads.php" method="POST">
                        <input type="hidden" name="MAX_FILE_SIZE" value="<?php
                        

                            $settingsXML 
simplexml_load_file('filesinfo/settings.xml');

                            echo 
$settingsXML->general->maximagesize*1000
                        
                        ?>
">
                        <input name="uploaded" type="file" id="uploaded">
                        <input type="submit" id="submitimage">
               </form>
            <!-- END FORM


            
            
            
            Results per page -->
            <div class="results-set" style="top:8px">
                            <div class="normal-res">
                                <span style="font-size:12px">results per page &nbsp; &nbsp; </span>
                                    <?php 
                                        $ra 
= array(5,10,20,50,100,200);
                                        
$x get_account($_SESSION['userID'])['results_images'];
                                        
                                        
$c=1;
                                        foreach(
$ra as $res) {
                                            
                                            
$d $c ' &nbsp;|&nbsp; ' '';
                                            echo (
$x != $res) ? '<a href="res-set.php?imgsperpage='.$res.'">'.$res.'</a>'.$d $res.$d;
                                            
$c++;
                                        }
                                    
?>
                            </div>    
                        </div>
                        
                        
                        
                        
                        
            <!-- Upload images -->            
            <div id="uploadedimages">
            <?php
                
                
                $array_img 
= array();
                
$array_mtime = array();
                
                
                
$directory = new DirectoryIterator('../images/');
                
                
                foreach (
$directory as $fileinfo) {
                
                        if (
$fileinfo->isFile()) {
                
                            
$name $fileinfo->getFilename();
                            
$ext $fileinfo->getExtension();
                            
$mtime $fileinfo->getMtime();
                
                        
                            if (
strpos('.png .jpg .gif',$ext) !== false) {
                                
                                
$array_img[]= $name;
                                
$array_mtime[] = $mtime;
                            }
                        }    
                }
                
                
                
rsort($array_mtime);
                include 
'navinfo.php';
                    
                
$c=0;
                
$r=0;
                
                foreach(
$array_mtime as $mt) {
                        
                        foreach(
$array_img as $imgkey=>$img) {
                                
                            if (
filemtime('../images/'.$img) == $mt) {
                                
                                if ((
$c >= $first) && ($c $last)){
                                
                                    
$r++;
                            
                                    
$im '../images/'.$img;
                                    echo 
'<div class="wrapper">'.PHP_EOL.' <div class="container"><a href="'.$im.'"><img src="'.$im.'"></a></div>'.PHP_EOL.'<div class="img-options"><a class="img-delete" href="?delimg='.$im.'&amp;max='.$ofp.'" onclick="return conf(this);"><span class="imd">[x]</span>&nbsp; Delete image</a>'.PHP_EOL.'</div></div>'.PHP_EOL;
                                }            
                                
$c++;
                                unset (
$array_img[$imgkey]);
                            }    
                        }
                }
            
?>
            </div>
            <!-- Upload images END -->
            
            
            <!-- Res nav -->
            <div id="res-nav">
            <?php include 'pagenav.php' ?>
            </div>
            
            
        </div>
    </div>
</body>
</html>