-2

I have looked at most of the suggested questions but can't find the answer I need.

I am using cakephp 2.x and I have a controller function as follows:

public function removeImage($image) {
    $p = '/explicit/path/to/website/domain.com/www/app/webroot/img/weddings/';
    $command = "rm ".$p.$image."*.jpg";
    $output = shell_exec($command);
    /* do something with $output */
}

The view file has this link

<?php echo $this->Html->link('remove image', array('controller' => 'weddings', 'action' => 'removeImage', 'p'.$aWeddings[$wedding['Wedding']['zenId']]['TitlePhoto']['Id'])); ?><?php endif; ?>

which gives me a string like 'p12321223213'.

I set the permissions to user:www-data and rw-rw-r--.

Now, when I click the link, not only does it not delete the file but it changes the permissions to www-data:www-data and rw-r--r--

the user is a member of www-data group.

Why is it not deleting the files?

Thanks

khany
  • 1,167
  • 15
  • 33
  • sounds like your code _is_ deleting the file and then immediately recreating it (attempting to delete a file will do only one of two things 1) delete the file 2) nothing). – AD7six Jul 29 '13 at 15:19
  • @AD7six I understand your logic but that doesn't explain why the 'new' filesizes are exactly the same as the old ones. – khany Jul 29 '13 at 22:51
  • How would it explain anything about the size of the file - I think you're stuck in "the problem is definitely this" mode right now, and need to look at "the problem" a bit different. e.g. right after deleting the file - log a dir listing. if it's _not_ there another process is recreating the file. Incidentally why use shell_exec instead of unlink or the file class? – AD7six Jul 29 '13 at 22:56
  • @AD7six before you go mentioning 'modes', I suggest you look at your first comment and advise yourself. Also, please read the page before replying as I have already commented about unlink. Exactly where is my code trying to re-create the file? – khany Jul 29 '13 at 23:01
  • @AD7six if it was realistic I wouldn't be posting a question here on SA. Thanks for your help, anyway. – khany Jul 29 '13 at 23:05
  • It's an observation, not an insult. Think about what you're saying right now "**calling rm** does not remove the file, reports that it works but instead changes ownership and permissions" - that's very unrealistic. Using a roundabout method to delete a file instead of unlink or the file class (neither of which are mentioned in the question) - isn't a solution. Also note that doing _anything_ via a get request is a bad idea, GET is [supposed to be a safe method](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html). – AD7six Jul 30 '13 at 07:13

1 Answers1

2

Try using native PHP function for deleting files: unlink().

AtLeT
  • 74
  • 1
  • 9