0

I am trying to unlink a file but keep getting a permission denied error.

The folder I am attempting to modify within has permissions 0775

I am trying to unlink file.pdf from unlink.php... The folder structure is as follows:

root / folder1(PasswordProtected) / unlink.php
root / folder2 / file.pdf

I have tried the following from unlink.php (but to no avail):

if(file_exists("../folder2/file.pdf"))
{
    chmod("../folder2/file.pdf",0777);
    unlink("../folder2/file.pdf");
}

I think my question is similar to permission denied - php unlink but honestly I just don't understand what I have to do...

Additional: If I change folder2 to 0777 in cPanel then I have no issues, but I don't want the public making changes to the file.. (is this correct? or have I misunderstood what 0777 does?)

Thanks for any help.!

Community
  • 1
  • 1
Zze
  • 18,229
  • 13
  • 85
  • 118
  • what is the ownership of folder2? the files? – nomistic May 05 '15 at 23:25
  • With hosting or on your own server? If its hosted, contact the hosting company. – developerwjk May 05 '15 at 23:25
  • Double check if path to file is correct from script perspective. – Michal Przybylowicz May 05 '15 at 23:32
  • @nomistic owner is user. – Zze May 05 '15 at 23:34
  • @MichalPrzybylowicz the file path is correct because I am able to upload files to the directory, I just can't remove files / unlink.? – Zze May 05 '15 at 23:34
  • you might try setting it to the server (e.g. apache) – nomistic May 05 '15 at 23:35
  • @nomistic So just to clarify, there doesn't seem to be anything out of place with my syntax? Sorry but I'm not really sure what you mean in your last comment.... – Zze May 05 '15 at 23:36
  • I meant `chown` the directory to the server and see if that works – nomistic May 05 '15 at 23:42
  • [get_current_user()](http://php.net/manual/en/function.get-current-user.php) to see what user PHP is running as. I'm assuming it is running under mod_php as apache or nobody. – Devon Bessemer May 05 '15 at 23:57
  • @Devon it returns jackjill... – Zze May 06 '15 at 00:05
  • I assume jackjill is the same user who owns this file then? For deleting a file, you need to have write access to the directory. So check your access level on folder2. – Devon Bessemer May 06 '15 at 00:36
  • @Devon .. oh sorry, yes it is.. .. So just to clarify, I am able to upload from the php script, but I can't unlink..? Also, plz see updated question. – Zze May 06 '15 at 00:38
  • I would assume you'd need the same permission to write a file to folder2 as you would to unlink. If you need `0777` permissions, then I'm assuming jackjill doesn't own folder2. – Devon Bessemer May 06 '15 at 00:39
  • @Devon I can write with 0775 perms i agree with your assumption, which is why i'm so confused at why this isn't working... P.s. I really appreciate the considerable effort you're putting in to assist me..... print_r(posix_getpwuid(fileowner("../folder2"))); returns [name] => jackjill print_r(posix_getpwuid(fileowner("../folder1"))); returns [name] => jackjill – Zze May 06 '15 at 00:49
  • That is strange. I'm at a loss then without more information or looking deeper into it first hand. – Devon Bessemer May 06 '15 at 00:50
  • @developerwjk We are going to contact the hosting company. - Cheers – Zze May 06 '15 at 04:52

1 Answers1

0

Server side issue. Full description of issue was not provided by hosting company. Now resolved.

Zze
  • 18,229
  • 13
  • 85
  • 118