Symfony3/Twig: How to get access to var folder in TWIG
I have images in my var folder under Symfony 3 -->
MyProject
- app
- bin
- web
- var --> uploads --> images --> myFile.jpg
I want to get access in my twig file to this jpeg file.
I use a global under
twig config: uploads_root_dir: /var/www/html/var/uploads
So my complete Url would be like this:
/var/www/html/var/uploads/images/myFile.jpg
But it is no Image shown. I can't use asset and I also don't want to. Is it possbile to get access to this file?
twig symfony
add a comment |
I have images in my var folder under Symfony 3 -->
MyProject
- app
- bin
- web
- var --> uploads --> images --> myFile.jpg
I want to get access in my twig file to this jpeg file.
I use a global under
twig config: uploads_root_dir: /var/www/html/var/uploads
So my complete Url would be like this:
/var/www/html/var/uploads/images/myFile.jpg
But it is no Image shown. I can't use asset and I also don't want to. Is it possbile to get access to this file?
twig symfony
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just/var/uploads.
– xabbuh
Mar 7 '17 at 14:33
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Create avaralias in your vhost pointing to /var/www/html/var/
– COil
Mar 7 '17 at 16:57
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59
add a comment |
I have images in my var folder under Symfony 3 -->
MyProject
- app
- bin
- web
- var --> uploads --> images --> myFile.jpg
I want to get access in my twig file to this jpeg file.
I use a global under
twig config: uploads_root_dir: /var/www/html/var/uploads
So my complete Url would be like this:
/var/www/html/var/uploads/images/myFile.jpg
But it is no Image shown. I can't use asset and I also don't want to. Is it possbile to get access to this file?
twig symfony
I have images in my var folder under Symfony 3 -->
MyProject
- app
- bin
- web
- var --> uploads --> images --> myFile.jpg
I want to get access in my twig file to this jpeg file.
I use a global under
twig config: uploads_root_dir: /var/www/html/var/uploads
So my complete Url would be like this:
/var/www/html/var/uploads/images/myFile.jpg
But it is no Image shown. I can't use asset and I also don't want to. Is it possbile to get access to this file?
twig symfony
twig symfony
asked Mar 7 '17 at 14:31
Zwen2012Zwen2012
1,11332042
1,11332042
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just/var/uploads.
– xabbuh
Mar 7 '17 at 14:33
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Create avaralias in your vhost pointing to /var/www/html/var/
– COil
Mar 7 '17 at 16:57
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59
add a comment |
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just/var/uploads.
– xabbuh
Mar 7 '17 at 14:33
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Create avaralias in your vhost pointing to /var/www/html/var/
– COil
Mar 7 '17 at 16:57
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like
/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just /var/uploads.– xabbuh
Mar 7 '17 at 14:33
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like
/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just /var/uploads.– xabbuh
Mar 7 '17 at 14:33
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Create a
var alias in your vhost pointing to /var/www/html/var/– COil
Mar 7 '17 at 16:57
Create a
var alias in your vhost pointing to /var/www/html/var/– COil
Mar 7 '17 at 16:57
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59
add a comment |
1 Answer
1
active
oldest
votes
Symfony (2 & 3) only expose the web folder.
You have two choices
- move your uploads to the web directory but it makes it accessible to everyone
- create a custom url that serve image if the user is authorized
exemple: (very abstract, just to have the general idea)
getImageAction($imageName)
{
if(! $this->isGranted('ROLE_USER')) {
// throw unauthaurize exception
}
$imagePath = $this->getParameter('kernel.root_dir').'../var/uploads/images/' . $imageName;
// then return the image file or its path
// [...]
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42650912%2fsymfony3-twig-how-to-get-access-to-var-folder-in-twig%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Symfony (2 & 3) only expose the web folder.
You have two choices
- move your uploads to the web directory but it makes it accessible to everyone
- create a custom url that serve image if the user is authorized
exemple: (very abstract, just to have the general idea)
getImageAction($imageName)
{
if(! $this->isGranted('ROLE_USER')) {
// throw unauthaurize exception
}
$imagePath = $this->getParameter('kernel.root_dir').'../var/uploads/images/' . $imageName;
// then return the image file or its path
// [...]
}
add a comment |
Symfony (2 & 3) only expose the web folder.
You have two choices
- move your uploads to the web directory but it makes it accessible to everyone
- create a custom url that serve image if the user is authorized
exemple: (very abstract, just to have the general idea)
getImageAction($imageName)
{
if(! $this->isGranted('ROLE_USER')) {
// throw unauthaurize exception
}
$imagePath = $this->getParameter('kernel.root_dir').'../var/uploads/images/' . $imageName;
// then return the image file or its path
// [...]
}
add a comment |
Symfony (2 & 3) only expose the web folder.
You have two choices
- move your uploads to the web directory but it makes it accessible to everyone
- create a custom url that serve image if the user is authorized
exemple: (very abstract, just to have the general idea)
getImageAction($imageName)
{
if(! $this->isGranted('ROLE_USER')) {
// throw unauthaurize exception
}
$imagePath = $this->getParameter('kernel.root_dir').'../var/uploads/images/' . $imageName;
// then return the image file or its path
// [...]
}
Symfony (2 & 3) only expose the web folder.
You have two choices
- move your uploads to the web directory but it makes it accessible to everyone
- create a custom url that serve image if the user is authorized
exemple: (very abstract, just to have the general idea)
getImageAction($imageName)
{
if(! $this->isGranted('ROLE_USER')) {
// throw unauthaurize exception
}
$imagePath = $this->getParameter('kernel.root_dir').'../var/uploads/images/' . $imageName;
// then return the image file or its path
// [...]
}
edited Nov 13 '18 at 8:49
answered Mar 7 '17 at 14:44
gotogoto
5,195102441
5,195102441
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f42650912%2fsymfony3-twig-how-to-get-access-to-var-folder-in-twig%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Your web server does probably not serve the whole tree of your filesystem. Instead the document is probably something like
/var/www/html. In your template you will then have to reference the path starting from the document root. It should then be just/var/uploads.– xabbuh
Mar 7 '17 at 14:33
Doesn't work, my path now is /var/uploads/images/myFile.jpg and the image is not shown
– Zwen2012
Mar 7 '17 at 14:41
Is that path actually accessible through your web server at all? And what path would that be there?
– xabbuh
Mar 7 '17 at 14:59
Create a
varalias in your vhost pointing to /var/www/html/var/– COil
Mar 7 '17 at 16:57
Why are you putting them under var? Symfony kind of wants you to put your "public" files under web. That's where your css, js, and images should go. Then in twig you can do something like: <img src="{{ asset('images/myFile.jpg') }}" /> and Symfony handles making sure the path is correct
– pogeybait
Mar 8 '17 at 10:59