Home  >  Article  >  Backend Development  >  在symfony2下转移本地文件夹

在symfony2下转移本地文件夹

WBOY
WBOYOriginal
2016-06-06 20:41:131144browse

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

upload到temp操作.

<code>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);

}
</code>

全部处理完毕后

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

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

移动后删除临时文件夹里的文件。
但是却出现了如下的错误信息。
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来更换了地址.

回复内容:

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

upload到temp操作.

<code>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);

}
</code>

全部处理完毕后

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

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

移动后删除临时文件夹里的文件。
但是却出现了如下的错误信息。
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来更换了地址.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn