drgweamoi473182981 2013-12-11 22:04
浏览 68
已采纳

管理作为base64字符串上载的文件

I am currently developing a website with AngularJS for the frontend, and a restful web service using Laravel framework (PHP5) as backend ; I am currently face to one problem, file uploading. I would like to have a very simple file uploaded, with a file input and just some copy into one of the server folder.

For now, I am using a directive in AngularJS that work great, and send my file using base64 url ; I am able to get this string inside my PHP backend, but unable to transform it to a file. For example, I would like to be able to get the filename, ext, ... and copy it to the server..

Any idea how to convert a base64 to a "file object" ? (Whether the solution is designed for Laravel et simple PHP doesn't bother me).

  • 写回答

1条回答 默认 最新

  • dongping1922 2013-12-11 22:11
    关注

    It's pretty easy just decode the base 64 String on your server and write into a file.

    Example if the image is located in forms image data and data were send as POST:

    file_put_contents('path/to/images/image.jpg', base_64_decode($_POST['image']));
    

    I'm not firm with laravel but I think there are better ways inside the Framework than accessing form data PHP's $_POST Array directly.

    To find of the filetype of the image have a look at finfo_buffer and see how to use for your case here

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条