php 在移动到另一个文件夹之前操作 tmp 文件夹中上传的图像/文件
我一直在以通常的方式上传后处理图像文件,例如将文件从 /tmp 文件夹移动到网站的首选文件夹。
现在我想通过将图像保存在临时文件夹中来操作图像,一旦我完成了它,我想将其移动到首选文件夹。
我想做的是......
- 显示一个非常简单的自定义文件上传对话框。
- 选择图像并单击上传。
- 该表单被提交到 iframe,以便我可以显示进度条。
- php 脚本将回显 javascript 代码,该代码将从 iframe 调用父窗口函数来通知图像已上传。
- 我想显示另一个对话框,它将显示 tmp 文件夹中的图像,以便用户可以调整大小和裁剪。
- 当用户选择图像上的要裁剪的区域时,我会将坐标发送到服务器并操作 tmp 文件夹中的图像。
- 图像处理完成后,我希望将最终图像移动到我的目标文件夹。
这是我的疑问。
- 临时图像将在 tmp 文件夹中保留多长时间。
- 如何在对话框中显示临时文件夹中的图像,因为我只有其物理路径。
- 我想我可以像
在 php 脚本中,我可以像 readfile('tmp/tmpfile') 一样读取图像。
那么,最后,从临时文件夹进行操作是否有效?它会有效/有启发性吗?可能会出现什么并发症?如果有的话。
我想为我的想法提供建议和替代方案。 谢谢。
I have been manipulating image files after uploading in the usual way like moving the file from the /tmp folder to a preferred folder of the site.
Now i want to manipulate images by keeping them in the temp folder and once i have done with it then i want to move it to the preferred folder.
What i am trying to do is ...
- Showing a very simple custom file upload dialog.
- Select an image and click upload.
- The form is submitted to an iframe so i can show a progressing bar.
- The php script will echo the javascript code which will call a parent window function from the iframe to notify that the image has been uploaded.
- I wanted to show another dialog which will display the image from the tmp folder so that the user can resize and crop.
- When the user selects a region on the image to crop i will send the coordinates to the server and will manipulate the image in the tmp folder.
- When the image manipulation has been done i want the final image to be moved to my target folder.
here are my doubts.
- How long will the temp image be there in the tmp folder.
- How do i display the image in the temp folder in my dialog box because i only have its physical path.
- I think i can do it like
<img src='fetchfromtmp.php?filename>
. isn't it? and in the php script i can readfile the image like readfile('tmp/tmpfile').
So, finally, will manipulating from temp folder holds good?. will it be effective/suggestive?. What could be the complications? if any.
I would like to have suggestions and alternatives for my idea.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这会给您的服务器带来漏洞。不要忘记临时文件夹默认也保存会话文件。
This would introduce a vulnerability to your server. Don't forget that the temporary folder holds the session files too by default.
我认为您不应该使用这样的临时文件夹,不幸的是,您必须创建自己的临时文件夹(或使用数据库来存储图像)。原因是你的第一点和第二点。 2:
I don't think you should use the temp folder like this, unfortunately, you will have to create your own (or use a database to store the images). The reasons are your point 1 & 2:
简短的回答是,这不是一个好主意。 tmp 文件夹中的文件可以在无需您干预的情况下删除,因此将它们移动到您自己的应用程序内的临时文件夹中,在那里进行处理,完成后将其移动到最终位置。
The short answer is , this is not a good idea. Files in the tmp folder can be deleted without ur intervention, so move them to a temp folder inside your own application, process it there and once done, move it to its final location.
。但是,您只需在上传后将图像移动到应用程序中的 tmp 目录即可解决所有这些问题。这样您就知道它不会被删除,您可以轻松地将其提供给用户,并且您知道您将能够读取该文件。
或者,如果您有权访问 php.ini 文件,则可以更改 upload_tmp_dir 并首先将图像上传到应用程序中的 tmp 目录。
However, you can solve all of these problems by simply moving the image to a tmp directory within your application after upload. That way you know it won't be deleted, you can easily serve it to the user and you know you'll be able to read the file.
Alternatively if you have access to your php.ini file you can change upload_tmp_dir and get the images uploaded to the tmp directory in your application in the first place.
文档对此非常清楚
所以你的想法行不通。另一方面,在大多数操作系统中,重命名文件是一项非常便宜的操作,因此没有充分的理由不立即移动临时文件。
the docs are quite clear about this
so your idea won't work. On the other side, renaming a file is a very cheap operation in most OS'es, so there are no good reasons NOT to move the temp file immediately.