首页 > 在symfony2下转移本地文件夹

在symfony2下转移本地文件夹

我处理一个excel文件. 因为有8000多行, 所以我先上传到temp文件夹里,用ajax分批处理. 全部处理后转移到别的文件夹里.

upload到temp操作.

public function fileUploadAction() {
    $content = $this->getRequest()->files->get('file0'); //to get file object
    $filename = $content->getClientOriginalName();

    $file_ext = $content->getClientOriginalExtension();
    $content->move(
            $this->get('kernel')->getRootDir() . '/../web/temp/', $filename
    );
    $path = $this->get('kernel')->getRootDir() . '/../web/temp/' . $filename;
    $return = $this->saveAolsurvey($path, 0);
    return new Response($return);

}

全部处理完毕后

$content = new File($path,true); //$path 是临时文件夹temp里的地址
    $filename = $content->getFilename();

    $date = date('ymd');
    $content->move(
            $this->get('kernel')->getRootDir() . '/../web/'.$date.'/', $filename
    );
    unlink($path);

移动后删除临时文件夹里的文件。
但是却出现了如下的错误信息。
Exception thrown when handling an exception (Symfony\Component\HttpKernel\Exception\FlattenException: Warning: json_encode() [function.json-encode]: Invalid UTF-8 sequence in argument in C:\wamp\www***\app\cache\dev\classes.php line 342)

上传时是使用uploadedFile , new的是file.
文件名并没有改变.

请各位大侠帮我解惑

=========================================================
我现在暂时用rename来更换了地址.

【热门文章】
【热门文章】