0

I have something like this:

$root = $_SERVER['DOCUMENT_ROOT']; 

and:

$coverv = $root . $coverv;
if(unlink($coverv)){
    echo "$coverv - ok<br>";
}

it shows me the echo imagelink - ok but the image still on the server.

eg:

/home/storage/8/d7/ef/myfolder/public_html/wp/2017/tay/tay-italy-may-2017-fri-apr-14-2017_t_8.jpg - ok

any ideas why the image still on the server?

RGS
  • 4,062
  • 4
  • 31
  • 67
  • 1
    Make sure that the user that runs PHP (if it's Apache, it's usually www-data) has permission to delete the files in that folder. Also, check your error log for potential error messages. – M. Eriksson Apr 16 '17 at 12:11
  • @MagnusEriksson I was looking at my folders, they are all 777 permition but the images are 666. any problems with this? – RGS Apr 16 '17 at 12:13
  • 1
    What does your error log say? (Just make sure that you have error_reporting turned on). Checking that should always be the first thing you do when you're debugging your code. – M. Eriksson Apr 16 '17 at 12:17
  • 1
    Try to use `file_exists()` function to ensure the path is correct. And related topic with possible answers: http://stackoverflow.com/questions/14997043/unlink-cannot-delete-file – JSLirola Apr 16 '17 at 12:19
  • 1
    @JSLirola - Just a tip, use `is_file()` instead of `file_exists()`, since the later returns true for directories as well and can result in unexpected behaviour if, for example, the path is concatenated wrong (like the filename is missing). – M. Eriksson Apr 16 '17 at 12:21
  • 1
    @MagnusEriksson You right. Thank you! – JSLirola Apr 16 '17 at 12:25
  • thank you friends. in fact my unlink was working. the problem is it is taking about 30 minutes to delete the file. not sure why, but, thank you very much. – RGS Apr 17 '17 at 18:08

0 Answers0