Haritz
Haritz

Reputation: 1752

Symfony2 and sudo privileges

I am developing an application using Symfony2. The problem I have is that when creating a folder throe a function in a entity the folder created has no sudo privileges, I would like to know how would it be possible to create the folder directly with sudo permissions. this is my code:

 protected function getUploadDirMark()
    {
        // get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
        return 'uploads/documents/'.$this->getIzenburua();
    }  

The 'uploads/documents/'.$this->getIzenburua(); folder has no sudo permissions, how can I create it with sudo privileges. Thanks.

Upvotes: 1

Views: 1084

Answers (3)

chiborg
chiborg

Reputation: 28064

If the regular chmod PHP function is not working, you can execute the chmod shell command with sudo permissions.

This is what it would look like in your Command class:

$uploadDirmark = $this->getUploadDirMark();
$dialog = $this->getHelperSet()->get('dialog');
$passwd = $dialog->ask($output, 'Please enter sudo password');
exec("echo $passwd | sudo -S chmod -R a+w $uploadDirmark");

This would make the directory and all its contents writable (and deletable) to all users. Modify the command as you see fit (see man chmod on the command line for more info). Opening it up like this is potentially dangerous, try putting the web server in the same group as the user that creates the files and use "g+w" instead of "a+w".

Upvotes: 1

Elnur Abdurrakhimov
Elnur Abdurrakhimov

Reputation: 44831

Why would you need sudo privileges for that? Since your application is run by a server under a particular user, it will have no problems serving files or folders it created.

Upvotes: 0

Nikita Gopkalo
Nikita Gopkalo

Reputation: 559

doen't this work ? chmod()

Upvotes: 0

Related Questions