phpsymfonytwigbundleuploadifive

Importing PHP file inside html.twig


I'm building a webapp with Symfony2 and I'm having great difficulty with getting php files to import into my code. I'm simply getting 404 - Not Found errors on the use of the php file. In a nutshell, I'm implementing the Uploadifive file uploader into my app and I have the js and css loading correctly by including them in my base.html.twig, which I extend on different pages within the app.

The uploadifive.php file is in the same folder as the css and js files, but I cannot seem to correctly get the path for it inside my code. I'm sure I'm missing something very simple here, but I cannot fix it :(

upload.html.twig

{% block content %}

    <input id="file_upload" type="file" name="file_upload" /> // This works

    <script type="text/javascript">
        $(function() {
            $('#file_upload').uploadifive({
                'uploadScript' : '%kernel.root_dir%/Resources/uploadifive/uploadifive.php'  // THIS DOES NOT WORK, 404's
                // Put your options here
            });
        });
    </script>

{% endblock %}

The files are located in /app/Resources/uploadifive/..

Can anyone help me out?


Solution

  • I think the problem is with how you reference the php file. You can only reference files that are publicly accessible and all of them are in web folder of symfony. They are mainly assets or uploaded files. So check your web folder I bet you can't find any php file there.

    For this case it shouldn't be web accessible. You have to create a controller using the uploadifive logics and create a route to serve that controller. So suppose in your route you defined /myuploader to be served by your controller. you can basically use '/myuploader' or {{ path('myuploader') }} if u want to use route id in your twig file and symfony already know where is it.