Giter VIP home page Giter VIP logo

Comments (7)

baudev avatar baudev commented on August 25, 2024 1

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?

from filemanagerbundle.

artgris avatar artgris commented on August 25, 2024 1

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.

from filemanagerbundle.

Telous avatar Telous commented on August 25, 2024

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

from filemanagerbundle.

baudev avatar baudev commented on August 25, 2024

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

from filemanagerbundle.

artgris avatar artgris commented on August 25, 2024

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

from filemanagerbundle.

baudev avatar baudev commented on August 25, 2024

Thanks @artgris, I will try it.

from filemanagerbundle.

Telous avatar Telous commented on August 25, 2024

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

from filemanagerbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.