Closed Telous closed 5 years ago
I'm currently using Symfony 3.1 and I was facing the same issue.
I thought a function was already coded to retrieve this url but it seems not. I checked directly in the template using the dump()
function of twig.
There is only a function (bellow) allowing to redirect URLs of the type "/admin/manager/file/..."
to "/web/upload/.../"
. EDIT: this is not even the case, it only retrieves the file directly from the file path.
So, I added the following attribute in File.php
constructor:
$this->websiteUrl = str_replace('\\', '/', $this->getProtocol().$_SERVER['HTTP_HOST'].str_replace($_SERVER['DOCUMENT_ROOT'], '', $file));
And the following method:
/**
* Return the current protocol used by the website
* @return string return "http" or "https"
* Source: https://stackoverflow.com/a/14270161/8219923
*/
private function getProtocol(){
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
return $protocol;
}
I don't know if a Pull Request is useful. What do you think about that @artgris?
I upgraded my project to S4 to use the bundle, buts this look fine to use on S3
I had some bugs during the installation but otherwise it works perfectly! The badge on the README indicated this:
Hi @Telous,
replace your dir path with a relative path:
artgris_file_manager:
# web_dir: web
conf:
default:
dir: "../web/img/uploads"
"../web" or "../public" are required to get 'public' image urls in filemanager.
Thx @baudev but binaryFileResponseAction is only used to obtain "private" images, when they are not in the web|public dir and not accessible by url.
if you remove".../web/", filemanage thinks it's a private directory
Thanks @artgris, I will try it.
Hi @Telous,
replace your dir path with a relative path:
artgris_file_manager: # web_dir: web conf: default: dir: "../web/img/uploads"
"../web" or "../public" are required to get 'public' image urls in filemanager.
I used this, but it generates an error: dir not found. Anyway, I updated the project to Symfony 4 and now it works fine. Thank you anyway
I try to use the bundle on a symfony 3.4 proyect, but when select an image to set i get the follow path:
/admin/manager/file/banner-5bc11d687d8ae.jpeg?module=1&conf=default&route=%5Cbanner
, instead ofimg/uploads/banners/banner-5bc11d687d8ae.jpeg
config.yml
I use a symfony buil-in-server to test.
i use this bundle on a symfony 4 proyect and no have any problems.