J
J
Jony13372015-11-13 16:15:45
PHP
Jony1337, 2015-11-13 16:15:45

Script to remove images from hosting in php?

Help need a script that will remove images from the hosting from a specific folder.
Let's say pictures in /domains/exemple.ru/public_html/mega1/f/images
I tried this script but it doesn't work

if (file_exists('./maps1/files'))
    foreach (glob('./maps1/files/*.png') as $file)
        unlink($file);

when I go to exemple.ru/mega1/f/clear.php photos from f/images will not be deleted

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Orlov, 2015-11-13
@Jony1337

you should have a script like this (other ways):

if (file_exists('./images/'))
    foreach (glob('./images/*.png') as $file)
        unlink($file);

this script will delete all png files inside the /images/ folder

M
Miku Hatsune, 2015-11-13
@Hatsune-Miku

file_exists() checks for the existence of a FILE, not a folder, is_dir() is needed here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question