php 在移动到另一个文件夹之前操作 tmp 文件夹中上传的图像/文件

发布于 2024-09-17 00:04:50 字数 732 浏览 4 评论 0原文

我一直在以通常的方式上传后处理图像文件,例如将文件从 /tmp 文件夹移动到网站的首选文件夹。

现在我想通过将图像保存在临时文件夹中来操作图像,一旦我完成了它,我想将其移动到首选文件夹。

我想做的是......

  1. 显示一个非常简单的自定义文件上传对话框。
  2. 选择图像并单击上传。
  3. 该表单被提交到 iframe,以便我可以显示进度条。
  4. php 脚本将回显 javascript 代码,该代码将从 iframe 调用父窗口函数来通知图像已上传。
  5. 我想显示另一个对话框,它将显示 tmp 文件夹中的图像,以便用户可以调整大小和裁剪。
  6. 当用户选择图像上的要裁剪的区域时,我会将坐标发送到服务器并操作 tmp 文件夹中的图像。
  7. 图像处理完成后,我希望将最终图像移动到我的目标文件夹。

这是我的疑问。

  1. 临时图像将在 tmp 文件夹中保留多长时间。
  2. 如何在对话框中显示临时文件夹中的图像,因为我只有其物理路径。
  3. 我想我可以像
  4. 在 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 ...

  1. Showing a very simple custom file upload dialog.
  2. Select an image and click upload.
  3. The form is submitted to an iframe so i can show a progressing bar.
  4. 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.
  5. I wanted to show another dialog which will display the image from the tmp folder so that the user can resize and crop.
  6. 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.
  7. When the image manipulation has been done i want the final image to be moved to my target folder.

here are my doubts.

  1. How long will the temp image be there in the tmp folder.
  2. How do i display the image in the temp folder in my dialog box because i only have its physical path.
  3. I think i can do it like <img src='fetchfromtmp.php?filename>. isn't it?
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

勿忘初心 2024-09-24 00:04:51
I think i can do it like <img src='fetchfromtmp.php?filename>. isn't it?

这会给您的服务器带来漏洞。不要忘记临时文件夹默认也保存会话文件。

I think i can do it like <img src='fetchfromtmp.php?filename>. isn't it?

This would introduce a vulnerability to your server. Don't forget that the temporary folder holds the session files too by default.

转角预定愛 2024-09-24 00:04:50

我认为您不应该使用这样的临时文件夹,不幸的是,您必须创建自己的临时文件夹(或使用数据库来存储图像)。原因是你的第一点和第二点。 2:

  1. 图像仅保证保留在临时文件夹中,直到上传图像的脚本完成运行为止。这意味着无论您的表单将其提交到什么脚本,都应该将其移动到安全的地方
  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:

  1. An image is only guaranteed to stay in the temp folder until the script that uploaded it is finished running. This means that whatever script your form submits it to should move it somewhere safe
  2. Usually, this temp folder will be somewhere that isn't visible to the user. You can hack something like you've suggested, but then you have to be very sure of what you're doing to avoid creating any security leaks.
本宫微胖 2024-09-24 00:04:50

简短的回答是,这不是一个好主意。 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.

×纯※雪 2024-09-24 00:04:50
  • 该图像将保存在 tmp 文件夹中,直至被删除。您的主机可能会定期清除它,但也可能不会,因此除非您将其删除,否则它将保留在那里。
  • 为了显示 tmp 文件夹中的图像,您必须使用脚本读取它并提供它(或使用 X-Sendfile)。
  • PHP 可以毫无问题地从 tmp 目录中读取数据

。但是,您只需在上传后将图像移动到应用程序中的 tmp 目录即可解决所有这些问题。这样您就知道它不会被删除,您可以轻松地将其提供给用户,并且您知道您将能够读取该文件。

或者,如果您有权访问 php.ini 文件,则可以更改 upload_tmp_dir 并首先将图像上传到应用程序中的 tmp 目录。

  • The image will be in the tmp folder until it is deleted. It's possible your host clears this out routinely, but probably not, so it will remain there unless you delete it.
  • In order to display an image from the tmp folder you'd have to read it in with a script and serve it (or use X-Sendfile).
  • PHP can read from the tmp directory without any problems

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.

七分※倦醒 2024-09-24 00:04:50

文档对此非常清楚

如果该文件尚未被移走或重命名,则该文件将在请求结束时从临时目录中删除。

所以你的想法行不通。另一方面,在大多数操作系统中,重命名文件是一项非常便宜的操作,因此没有充分的理由不立即移动临时文件。

the docs are quite clear about this

The file will be deleted from the temporary directory at the end of the request if it has not been moved away or renamed.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文