Where and how create cron job

Hi all
i try to create a cron job
i want delete all picture ( jpg) that i have in the ftp , not in the “public_htlm” folder, but in the “scan/perso” folder.
all picture that have more than 10 days

could you help me to write the php code ?
where i must put this code (folder ) ?
and what sort of link i must write when i’ll create the cron job ?

sorry for my english and thanks for your help
:grin:

Hi,
ok
and the script could be this ; ??

<?php exec('find . -name "*.jpg" -mtime -10 -exec rm {} \;'); ?>

image

Hey there,

The exec() function is disabled on 000webhost :slight_smile:

ok
So how i can do ?
could you help me , please ?

Good day @boismal!

000webhost supports Cronjobs. Go to 000webhost cPanel > Settings > Cronjobs to setup one.

Cronjobs can execute only PHP scripts. Core server functions such as exec() are disabled for security reasons; you’ll need to use an alternative code. What do you want to achieve?

Hi ,
i want to delete automatically , all picture ( jpg) older than 15 days

This should to the desired task.

<?php

$fileSystemIterator = new FilesystemIterator('scan/perso');
$now = time();

foreach ($fileSystemIterator as $file) {
    if ($now - $file->getCTime() >= 60 * 60 * 24 * 15 && pathinfo('scan/perso/' . $file -> getFilename(), PATHINFO_EXTENSION) == 'jpg') 
        unlink('scan/perso/'.$file->getFilename());
}

hi ,
thanks , but it doesn’t work…

i put this code un the notepad file, rename extension with php (effacer.php)
add this in the folder /script
and create a cron job with this link :https://myname.000webhostapp.com/script/effacer.php
and all picture are always here
:wink:

So !!! do you have idea , how i can do ??
:frowning:

@teodor please check back

I offered you a sample code. If you want custom code but you have no coding knowledge, you should either wait for a reply from another forum member, ask your question somewhere else, or hire a freelancer to write the code for you.

Our duty as moderators is to provide 000webhost services support. Writing PHP code for our customers is not related to it.


Check out these replies from Stackoverflow. Adapt the script to your needs:

ok Thanks for your help
i will triy to do this

1 Like