• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Simple file manager

Can you please make like it shows ip under image? Like i can ban if wanted ^^ , or delete all images from that ip at once
 
Showing the ips are impossible, because chevereto do not log them in any database. You will need to wait for 2.1.
 
Darkmax said:
Hey guys,

Here's a very simple file manager i just coded. This will get all the images from your images and thumbs folder and you'll be able to delete any with a single click.

When you delete an image it will also delete the thumb. If the image or the thumb doesn't exist, it will delete whatever exists (the image or the thumb) if none exist, well, you will get a message telling you that none exist and could not delete them.

First, create a new php file where your index.php is. I called mine admin.php

Add the following code inside the newly created php file:
PHP:
<?php

// SETTINGS
$config['admin_ip'] = '111.111.111.111';
$config['images_dir'] = 'images/';
$config['thumbs_dir'] = 'images/thumbs/';
$config['image_formats'] = 'png,jpg,gif,bmp';
$config['images_per_row'] = '8';


/* check admin ip */
if($_SERVER['REMOTE_ADDR'] != $config['admin_ip']) { die('you do not have access to this file.'); }


// ========== DELETE IMAGE START ========== //
if(isset($_REQUEST['delete'])) {

/* check if image exists */
if(!file_exists($config['images_dir'].$_REQUEST['delete'])) {
echo '<span style="color:red;">image does not exist ('.$config['images_dir'].$_REQUEST['delete'].')</span><br />';
$chk_image = 1;
}

/* check if image's thumb exists */
if(!file_exists($config['thumbs_dir'].$_REQUEST['delete'])) {
echo '<span style="color:red;">thumb does not exist ('.$config['thumbs_dir'].$_REQUEST['delete'].')</span><br />';
$chk_thumb = 1;
}


/* delete image */
if($chk_image != 1) {
if(!@unlink($config['images_dir'].$_REQUEST['delete'])) {
/* it worked */
echo 'could not delete image ('.$config['images_dir'].$_REQUEST['delete'].')<br />';
} else {
/* could not delete, display error */
echo '<span style="color:green;">image deleted successfully !</span><br />';
}
}

/* delete thumb */
if($chk_thumb != 1) {
if(!@unlink($config['thumbs_dir'].$_REQUEST['delete'])) { 
/* it worked */
echo 'could not delete thumb ('.$config['images_dir'].$_REQUEST['delete'].')<br />';
} else {
/* could not delete, display error */
echo '<span style="color:green;">thumb deleted successfully !</span><br />';
}
}

}
// ========== DELETE IMAGE END ========== //

echo '<table cellspacing="3" cellpadding="0">';
echo '<tr>';
$cnt = 0;
foreach (glob("".$config['images_dir']."*.{".$config['image_formats']."}", GLOB_BRACE) as $filename) 
{
$image_name = explode($config['images_dir'],$filename);

$cnt++;
if($cnt % $config['images_per_row'] == 1) { echo '</tr><td></td><tr>'; }
	
echo '<td align="center" style="border:1px solid #cccccc;background:#eeeeee;padding:3px;">';
echo '<a href="./?v='.$image_name[1].'" target="_blank">';
echo '<img src="'.$config['thumbs_dir'].$image_name[1].'" style="margin-bottom:2px;border:0px;"></a><br />';
echo '<a style="font-size:11px;font-family:Arial;text-decoration:none;" href="?delete='.$image_name[1].'">delete</a>';
echo '</td>';

}
echo '</tr>';
echo '</table>';
?>

Make sure you edit the settings:
PHP:
// SETTINGS
$config['admin_ip'] = '111.111.111.111';
$config['images_dir'] = 'images/';
$config['thumbs_dir'] = 'images/thumbs/';
$config['image_formats'] = 'png,jpg,gif,bmp';
$config['images_per_row'] = '8';

you will only be able to access the file through the IP you set in the settings.

Here's a preview:
hisvo.jpg


If you purchased my login/database MOD this will not remove the images from the database, if you want this to also remove images from the database you need to:

1.- include my db connection file.
PHP:
include('includes/dmx.sql.php');

2.- add the following query below the "/* it worked */" comment:
PHP:
@mysql_query("DELETE FROM uploaded_images WHERE file = '".mysql_real_escape_string($_REQUEST['delete'])."'");

happy valentine's day !

Image in database doesnt get deleted :(
I put this after <?php:
"include('includes/dmx.sql.php');"

and "@mysql_query("DELETE FROM uploaded_images WHERE file = '".mysql_real_escape_string($_REQUEST['delete'])."'");"
After "/* it worked */".

Do you know how to get this to work? :)
 
Danny.Domb said:
Here with the logout button on the top right corner.

As for the pagination, I don't intend to do it... It would require to recode most of the actual code...

PHP:
<?php
session_start();
define('access', 'admin');
 
include('includes/chevereto.php');
 
// SETTINGS
$config = array (
    'password' => 'admin123',
    'image_formats' => array('gif', 'png', 'jpg', 'jpeg'),
    'images_per_row' => 8,
    'confirm' => true,
    'order' => 'inverse' // normal => (From the oldest to the latest) inverse => (from the latest to the oldest)
);
 
// FUNCTIONS
function deleteFile($path, $type = 'image')
{
    if(unlink($path))
    {
        showMessage($type.' deleted successfully !', true);
    }
    else
    {
        showMessage('Could not delete '.$type.' ('.__CHV_PATH_IMAGES__.$_GET['delete'].')', false);
    }
}
 
function showMessage($msg, $success = true)
{
    $color = ($success) ? 'green' : 'red';
    print('<p style="color:'.$color.';">'.$msg.'</p>');
}

function fileExtension($fileName)
{
    return substr($fileName, strrpos($fileName, '.') + 1);
}

function getFiles($allowedExt)
{
    $array = array();
 
    if ($handle = opendir(__CHV_PATH_IMAGES__))
    {
        while (false !== ($file = readdir($handle)))
        {
        	if ($file != '.' && $file != '..' && in_array(fileExtension($file), $allowedExt))
            {
                $array[] = array('name' => $file, 'time' => filemtime(__CHV_PATH_IMAGES__.$file));
            }
        }
        closedir($handle);
    }
 
    return $array;
}

function sortByTimeNormal($a, $b)
{
	if ($a['time'] == $b['time'])
	{
        return 0;
    }
    
    return ($a['time'] < $b['time']) ? -1 : 1;
}

function sortByTimeInverse($a, $b)
{
	if ($a['time'] == $b['time'])
	{
        return 0;
    }
    
    return ($a['time'] < $b['time']) ? 1 : -1;
}

// Variables Declaration
$content = '';
$javascript = '';
 
// Login validation
if (isset($_POST['password']) && $_POST['password'] === $config['password'])
{
    $_SESSION['login'] = true;
}

if (isset($_SESSION['login']) && $_SESSION['login'] && isset($_POST['logout']))
{
	$_SESSION['login'] = false;
}

// Admin content
if (isset($_SESSION['login']) && $_SESSION['login'])
{
    // Since we want to stay XHTML Valid…
    ob_start();
 
    // ========== DELETE IMAGE START ========== //
    if(isset($_POST['delete']))
    {
        // delete image
        if(file_exists(__CHV_PATH_IMAGES__.$_POST['delete']))
        {
            deleteFile(__CHV_PATH_IMAGES__.$_POST['delete']);
        }
        else
        {
            showMessage('Image does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
        }
 
        // delete thumb
        if(file_exists(__CHV_PATH_THUMBS__.$_POST['delete']))
        {
            deleteFile(__CHV_PATH_THUMBS__.$_POST['delete'], 'thumb');
        }
        else
        {
            showMessage('Thumb does not exist ('.__CHV_PATH_IMAGES__.$_POST['delete'].')', false);
        }
    }
    // ========== DELETE IMAGE END ========== /
    //$images = glob("".__CHV_PATH_IMAGES__."*.{".$config['image_formats']."}", GLOB_BRACE);
    
    $images = getFiles($config['image_formats']);
    
    if ($config['order'] == 'normal')
   		usort($images, 'sortByTimeNormal');

   	else
		usort($images, 'sortByTimeInverse');
		
		
	// Logout button
	print ('<div style="float: right;"><form action="#" method="post"><input type="submit" name="logout" value="Log Out" /></form></div>');
 
    echo '<table cellspacing="3" cellpadding="0">';
    echo '<tr>';
 
    for ($i = 0; $i < count($images); $i++)
    {
       	$name = basename($images[$i]['name']);
 
        if ($i % $config['images_per_row'] == 0) { echo '</tr><td></td><tr>'; }
 
        echo '<td align="center" style="border:1px solid #cccccc;background:#eeeeee;padding:3px;">';
        echo '<a href="./?v='.$name.'" target="_blank">';
        echo '<img src="'.absolute_to_url(__CHV_PATH_THUMBS__.$name).'" style="margin-bottom:2px;border:0px;"></a><br />';
        echo '<span style="font-size:11px;font-family:Arial;text-decoration:none;">'.date('F d, Y H:i:s', $images[$i]['time']).'</span><br />';
        echo '<a style="font-size:11px;font-family:Arial;text-decoration:none;" class="_delete" alt="'.$name.'" href="#">Delete</a>';
        echo '</td>';
    }
 
    echo '</tr>';
    echo '</table>';
 
    $content = ob_get_contents();
    ob_end_clean();
    
    $javascript = '';
 
}
else
{    
    $content = '
        <form action="#" method="post">
            <p><span style="font-weight: bold;">Password:</span> <input type="password" name="password" /></p>
            <p><input type="button" value="Login" name="login" /></p>
        </form>
    ';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd[/url]">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Chevereto Admin</title>
    </head>
 
    <body>
        <?php print($content); ?>
    </body>
</html>
<script type="text/javascript" src="<?php print(absolute_to_url(__CHV_PATH_SYSTEM_JS__)); ?>jquery.min.js"></script>
<script type="text/javascript">
$(function (){
	$("._delete").click(function() {
		var element = $(this);
	
		<?php if($config['confirm']) { print('if (window.confirm("Are you sure you wish do delete this file?")) {'); } ?>
		
			$.post("admin.php", {delete: $(this).attr('alt')}, function() {
					
			}).success(function() {
				$(element).parent().remove();
			}).error(function() {
				alert('For some obscure reason, we could not delete the file');
			});
		
		<?php if($config['confirm']) { print('}'); } ?>
	});
});
</script>

Hey sheep use this one it works. :)
 
I am continually getting the error: "you do not have access to this file."

I'm accessing it via the IP too, yet no go.
 
Back
Top