artgris / FileManagerBundle

FileManager is a simple Multilingual File Manager Bundle for Symfony
MIT License
175 stars 90 forks source link

Images routes #26

Closed Telous closed 5 years ago

Telous commented 5 years ago

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 of img/uploads/banners/banner-5bc11d687d8ae.jpeg

config.yml

artgris_file_manager:
    # web_dir: web
    conf:
        default:
            dir: "img/uploads"

I use a symfony buil-in-server to test.

i use this bundle on a symfony 4 proyect and no have any problems.

baudev commented 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.

https://github.com/artgris/FileManagerBundle/blob/4e35c8dad71d1a7bfe3b43136d6bcd1c691affe7/Controller/ManagerController.php#L287-L301

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?

Telous commented 5 years ago

I upgraded my project to S4 to use the bundle, buts this look fine to use on S3

baudev commented 5 years ago

I had some bugs during the installation but otherwise it works perfectly! The badge on the README indicated this:

artgris commented 5 years ago

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.

artgris commented 5 years ago

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

baudev commented 5 years ago

Thanks @artgris, I will try it.

Telous commented 5 years ago

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