Post: PHP/Cron question
11-17-2011, 06:49 PM #1
ThereThatGuy
Porkey The Pig Is My Nigg
(adsbygoogle = window.adsbygoogle || []).push({}); Original question

Hey guys, I have my ScreenSnpr setup, I want to setup a Cron to auto delete images after 24 hrs

From what I understand this is the basic code
    find /directory -maxdepth 1 -type f -mtime +7 -exec rm -f {} \;

But I want to be able to delete the images with an exception to the index.php file

Example the screensnpr is index.php file is
You must login or register to view this content.
or
/public_html/snpr/images

whatever you prefer.

Or maybe just a PHP script with a purge button.


I mean I made a code for that but I can't get it to work...

HTML=
    <select name="dtime">
<option selected="selected"></option>
<option value="1">1 minute</option>
<option value="5">5 minutes</option>
<option value="10">10 minutes</option>
<option value="15">15 minutes</option>
<option value="20">20 minutes</option>
<option value="25">25 minutes</option>
<option value="30">30 minutes</option>
<option value="60">1 hour</option>
<option value="300">5 hours</option>
<option value="720">12 hours</option>
<option value="1440">1 day</option>
</select>


Php would be=
    function deleteImage($time, $img)
{
if ($time != 0 || !empty($time))
{
$expiretime = $time;

$FileCreationTime = filectime($img);
$FileAge = time() - $FileCreationTime;

if ($FileAge > ($expiretime * 60))
{
unlink($img);
}
}
}


so Usage would be=
    $deletetime = (!empty($_POST['dtime'])) ? $_POST['dtime'] : 0;
$image = 'i/' . $filename;

// Delete image
deleteImage($deletetime, $image);



But like I said, It does not work and there is no exception..

Help anyone?!?

Thanks
TTG


Fixed code


Place this in a folder before your images, EX
/public_html/snpr/images is where your index.php file is and /public_html/snpr/images/image is where your images are.
    <?php

define('PATH', 'image/'Winky Winky;

function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.'Winky Winky;
destroy($dir.$file.'/'Winky Winky;
rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';



?>


You can just go to the URL to execute the script
or the crone code

    wget https://location.com/where/your/file/is.php >/dev/null 2>&1


This is the php for the snpr itself.
    <?php
$img = "https://YOUR-SITE/snpr/images/image/".$_GET["img"];
?>
<?php
if($img=="") { echo ""; } else { echo "<img src='" . $img . "' border=10 />" ; } ?>

If you need any help Just QUOTE me. Also, A special thanks to Alfa for helping me with the screensnpr error.
(adsbygoogle = window.adsbygoogle || []).push({});
11-17-2011, 06:52 PM #2
Alfa
Banned
Originally posted by ThereThatGuy View Post
Hey guys, I have my ScreenSnpr setup, I want to setup a Cron to auto delete images after 24 hrs

From what I understand this is the basic code
    find /directory -maxdepth 1 -type f -mtime +7 -exec rm -f {} \;

But I want to be able to delete the images with an exception to the index.php file

Example the screensnpr is index.php file is
You must login or register to view this content.
or
/public_html/snpr/images

whatever you prefer.

Or maybe just a PHP script with a purge button.


I mean I made a code for that but I can't get it to work...

HTML=
    <select name="dtime">
<option selected="selected"></option>
<option value="1">1 minute</option>
<option value="5">5 minutes</option>
<option value="10">10 minutes</option>
<option value="15">15 minutes</option>
<option value="20">20 minutes</option>
<option value="25">25 minutes</option>
<option value="30">30 minutes</option>
<option value="60">1 hour</option>
<option value="300">5 hours</option>
<option value="720">12 hours</option>
<option value="1440">1 day</option>
</select>


Php would be=
    function deleteImage($time, $img)
{
if ($time != 0 || !empty($time))
{
$expiretime = $time;

$FileCreationTime = filectime($img);
$FileAge = time() - $FileCreationTime;

if ($FileAge > ($expiretime * 60))
{
unlink($img);
}
}
}


so Usage would be=
    $deletetime = (!empty($_POST['dtime'])) ? $_POST['dtime'] : 0;
$image = 'i/' . $filename;

// Delete image
deleteImage($deletetime, $image);



But like I said, It does not work and there is no exception..

Help anyone?!?

Thanks
TTG


make the images save inside another folder where only the images are located then link it to that directory

The following user thanked Alfa for this useful post:

ThereThatGuy
11-17-2011, 06:57 PM #3
ThereThatGuy
Porkey The Pig Is My Nigg
Originally posted by Alfa View Post
make the images save inside another folder where only the images are located then link it to that directory


Can't do that, the images have to be in the same folder as the PHP file for the snpr to work :(
11-17-2011, 07:00 PM #4
Alfa
Banned
Originally posted by ThereThatGuy View Post
Can't do that, the images have to be in the same folder as the PHP file for the snpr to work :(


$img = "/images/".$_GET['img'];

The following user thanked Alfa for this useful post:

ThereThatGuy
11-17-2011, 07:12 PM #5
ThereThatGuy
Porkey The Pig Is My Nigg
Originally posted by Alfa View Post
make the images save inside another folder where only the images are located then link it to that directory


Gotz it, Forgot to name the parent directory Smile

So if the images are in
    /public_html/snpr/images/image
and the file is in
    /public_html/snpr/images


I need to put
    find /public_html/snpr/images/image -maxdepth 1 -type f -mtime +7 -exec rm -f {} \;


right? And where would I change the time...

I know shit about Cron lol
11-17-2011, 07:35 PM #6
Alfa
Banned
Originally posted by ThereThatGuy View Post
Gotz it, Forgot to name the parent directory Smile

So if the images are in
    /public_html/snpr/images/image
and the file is in
    /public_html/snpr/images


I need to put
    find /public_html/snpr/images/image -maxdepth 1 -type f -mtime +7 -exec rm -f {} \;


right? And where would I change the time...

I know shit about Cron lol


not sure about that ''/ iv actually never even heard of Cron before :p
11-17-2011, 08:12 PM #7
ThereThatGuy
Porkey The Pig Is My Nigg
Originally posted by Alfa View Post
not sure about that ''/ iv actually never even heard of Cron before :p


Okay, After a few hrs of trouble shooting turns out my server would not except my path the a "/" befor it..

So my dinal code is

    
<?php

define('PATH', 'image/'Winky Winky;

function destroy($dir) {
$mydir = opendir($dir);
while(false !== ($file = readdir($mydir))) {
if($file != "." && $file != "..") {
chmod($dir.$file, 0777);
if(is_dir($dir.$file)) {
chdir('.'Winky Winky;
destroy($dir.$file.'/'Winky Winky;
rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
else
unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
}
}
closedir($mydir);
}
destroy(PATH);
echo 'all done.';



?>



Smile

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo