Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images routes #26

Closed
Telous opened this issue Nov 20, 2018 · 7 comments
Closed

Images routes #26

Telous opened this issue Nov 20, 2018 · 7 comments

Comments

@Telous
Copy link

Telous commented Nov 20, 2018

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
Copy link

baudev commented Nov 21, 2018

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.

* @Route("/file/{fileName}", name="file_manager_file")
*
* @param Request $request
* @param $fileName
*
* @return BinaryFileResponse
*
* @throws \Exception
*/
public function binaryFileResponseAction(Request $request, $fileName)
{
$fileManager = $this->newFileManager($request->query->all());
return new BinaryFileResponse($fileManager->getCurrentPath().DIRECTORY_SEPARATOR.urldecode($fileName));
}

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
Copy link
Author

Telous commented Nov 21, 2018

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

@baudev
Copy link

baudev commented Nov 21, 2018

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

@artgris artgris added bug and removed bug labels Nov 22, 2018
@artgris
Copy link
Owner

artgris commented Nov 22, 2018

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
Copy link
Owner

artgris commented Nov 22, 2018

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
Copy link

baudev commented Nov 22, 2018

Thanks @artgris, I will try it.

@Telous
Copy link
Author

Telous commented Nov 22, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants