Where and how create cron job


#1

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:


#3

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

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

#4

image


#5

Hey there,

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


#6

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


#7

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?


#8

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


#9

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());
}

#10

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:


#11

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


#12

@teodor please check back


#13

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:


#14

ok Thanks for your help
i will triy to do this