Warning: unlink() but file is removed

I am using the code below remove an image file. The files is removed but there is still an error shown. Any suggestions?

Warning: unlink() [function.unlink]: open_basedir restriction in effect. File() is not within the allowed path(s):

<?php
session_start(); //session start

if(isset($_SESSION['access_token']) && $_SERVER['REQUEST_METHOD'] == 'POST')
{
    $check_image = glob('../uploads/logo_'.$_SESSION['relatie_id'].'.*');
    unlink($check_image[0]);

    echo '<div class="alert alert-success text-center" role="alert">Met succes verwijderd.</div>';
}
?>

1 answer

  • answered 2017-06-17 19:06 Muhammad Usman

    Try this function

     function delete($dir, $file) {
       $file = $dir . '/' . $file;
       if ((file_exists($file)) && (@unlink($file)) ) {
         return true;
       }
       return false;
     }