将请求中的文件移动或复制到多个位置 [英] Move or copy a file from the request to multiple locations

查看:146
本文介绍了将请求中的文件移动或复制到多个位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Laravel并进行输入和文件上传。此页面用户想要对订单进行更改。最终目标是采取这个输入,并将其应用于多个订单。

我可以重复使用每个订单的输入。但是,如果将请求中的文件复制到多个目录中,这将是一个好方法吗?例如,在文档中,我最初有: $ request-> file('photo') - > move($ destinationPath,$ fileName); 罚款一个订单。但是现在我想把它应用到许多命令中,因为它不存在,所以我不能再从请求中移动相同的文件。



它看起来像UploadedFile对象没有 copy()方法。任何想法,将不胜感激。谢谢。

解决方案

如果我可以提出一个建议,假设这些文件将保持不变用户按顺序修改这些文件),我认为将文件的一个副本存储在服务器上并使用数据库表来确定该文件属于哪个订单并将其全部管理在表中是有意义的。您可能需要创建一个文件表和一个 file_order 表,并为它赋予一个多对多的关系 orders 表,但是最后如果允许这些文件很大,可以为你节省很多空间,而且在我看来,管理起来更容易一些。

b $ b

I'm using Laravel and taking in input and file uploads. This page takes changes that users want to make to an order. The end goal is to take this input and apply it to multiple orders.

I can reuse the input for each of the orders. But what would be a good way for me to copy that file in the request to multiple directories? For example, as in the documentation, I originally have: $request->file('photo')->move($destinationPath, $fileName); which works fine for one order. But now that I want to apply it to many orders, I can't move that same file from the request anymore since it doesn't exist.

And it looks like the UploadedFile object doesn't have a copy() method. Any ideas would be appreciated. Thank you.

解决方案

If I may make a suggestion assuming these files are going to stay the same (you aren't allowing your users to modify these files by order), I think it makes sense to store one copy of the file on the server and use a database table to determine which orders that file belongs to and manage it all in the table. You may need to create a files table and an file_order table and give it a many to many relationship to your orders table but in the end, if these files are allowed to be large, could save you a lot of space and in my opinion, make it easier to manage.

这篇关于将请求中的文件移动或复制到多个位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆