0

I am trying to use the cookbook example on how to upload fiels with symfony2 : http://symfony.com/doc/2.0/cookbook/doctrine/file_uploads.html

The problem is that I am not able to get the path of the web folder.

Here are some details: In my web folder, I have a structure like that:

/web
    /bundles
        /sciforumversion2
            /images

And from the entity, I I trying to get the folder path and save my image in the /images folder

For that, I am using:

protected function getUploadRootDir()
{
    // the absolute directory path where uploaded
    // documents should be saved
    return __DIR__ . '/../../../../web/'.$this->getUploadDir();
}

protected function getUploadDir()
{
    // get rid of the __DIR__ so it doesn't screw up
    // when displaying uploaded doc/image in the view.
    return 'sciforumversion2/bundles/images';
}

But I am getting then the exception that the directory can't be created:

Unable to create the "/home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/conference" directory 

Any idea on how could I get the web folder url and why the solution proposed by the symfony cookbook is not working is mostly welcome.

Thank you very much. Thank you.

2
  • maybe github.com/dustin10/VichUploaderBundle would be something nice for you Commented Dec 14, 2012 at 10:39
  • Thank you, but I have everythink working in my personal bundle, except the dir problem, so I prefer to use what I have Commented Dec 14, 2012 at 10:45

1 Answer 1

2

The path seems to be correct.

Probably you should give it the correct permissions.

Try this first:

chmod 777 /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/

If that works, it's a permission issue. Set the owner and group to www-data using:

chown www-data:www-data /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/
chmod 755 /home/milos/workspace/conference2.0/src/SciForum/Version2Bundle/Entity/../../../../web/sciforumversion2/bundles/images/
Sign up to request clarification or add additional context in comments.

1 Comment

That is, it works now, thanks a lot. A +1 from me and I have confirmed your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.