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#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。