J
J
Jony13372015-11-12 21:46:33
PHP
Jony1337, 2015-11-12 21:46:33

Removing files from hosting?

I have a website and every day there is a rush of files, so I need it so that when I go to site.ru/maps1/clear.php, all files from maps1/files are deleted, so I tried this script does not work

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

added a directory in the script also does not work
when I go to site.ru/maps1/clear.php -
Server error
500
Permissions for files to be deleted ( 777)
Permissions clear.php (755
upd^
<?php>
if (file_exists('./maps1/files'))
foreach (glob('./maps1/files/*.png') as $file)
unlink($file);
?>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vanya Zyuzgin, 2015-11-12
@site2life

Problem with directory and file paths. Try adding paths to full absolute ones, like /var/www/site.ru/maps1/files

R
Robot, 2015-11-12
@iam_not_a_robot

If the PHP script files hosted on your hosting have access rights 777, then the execution of these scripts may be blocked by the server and you will be shown an error 500. This happens due to the fact that the access rights 777 allow everyone to make any changes to this file, which significantly affects the security and integrity of your site.

Most likely, the php file needs just 755 rights, but 777 for the deleted files, you can check the correctness of the path like this:
if (file_exists($filename)) {
    echo "Файл $filename существует";
} else {
    echo "Файл $filename не существует";
}

A
Artem Spiridonov, 2015-11-12
@customtema

exec('rm -rf maps1/files/*');

M
maximw, 2015-11-13
@maximw

If the script is in the same directory where you need to delete the files.

<?php
if (file_exists(__DIR__.'/maps1/files')) {
    foreach (glob(__DIR__.'/maps1/files/*.png') as $file) {
        unlink($file);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question