Symfony3导入excel文件的绝对路径

时间:2018-01-29 15:11:13

标签: excel symfony

我必须将一些excel文件的内容导入到数据库中,这些文件是从usb-stick或其他位置选择的。我在for循环中动态生成输入(type = file),并可以为每一行选择excel文件。单击导入按钮后,我想在控制器操作中将所选文件插入到数据库中。如何获得所选文件的完整/绝对路径?我只是得到Fakepath + Excel-Filename。或者获得某个文件的真实路径的最佳方法是什么?非常感谢

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

除了@Romain Norsberg的回答:

The documentation向您展示如何上传文件,但如果您只是想利用它的内容,可以直接保存文件!

$(function() {
$(document).scroll(function() {
    var y = $(window).scrollTop();
    console.log(y);

    if (y >= 200) {
        $('.product__add-to-cart-button').click(function() {
            // your statements;
            $(".site-header").addClass("site-header--fixedd").removeClass("site-header--transparent");
            $("#crazy-pineapple, #coco-twist, #crunchy-joy, #nutty-chia").css('margin-top', 143);
            setTimeout(function() {
                $(".site-header__cart-bubble").removeClass("bubblenormal").addClass("bubblevisible");

            }, 300);
            setTimeout(function() {
                $(".site-header__cart-bubble").removeClass("bubblevisible").addClass("bubblenormal");
            }, 700);
            setTimeout(function() {
                $(".site-header").removeClass("site-header--fixedd");
                $(".site-header").addClass("site-header--fixeddd");
            }, 1200);
            setTimeout(function() {
                $("#crazy-pineapple, #coco-twist, #crunchy-joy, #nutty-chia").css('margin-top', 0);
                $(".site-header").addClass("site-header--transparent");
                $(".site-header").removeClass("site-header--fixedd");
                $(".site-header").removeClass("site-header--fixeddd");
            }, 1600);
        });
    }
});

答案 2 :(得分:0)

你能做什么

 if($request->isMethod('post')) {
        // retrieve the uploaded file
        $file = $request->files->get('inputExcel');
        // retrieve the web directory path
        $webDir = $this->get('kernel')->getProjectDir() . "/web";
        //Move the file in your web directory
        $file->move($webDir, $file->getClientOriginalName());
        $pathFile = $webDir.'/'. $file->getClientOriginalName();
        //call your service to save data from file
        $saveDataFromFile->($pathFile);
        //remove the file after treatment
        unlike($pathFile);
}