PHP:如何将上传的临时文件复制到多个地方?

PHP: how do I copy a temp file upload to multiple places?(PHP:如何将上传的临时文件复制到多个地方?)
本文介绍了PHP:如何将上传的临时文件复制到多个地方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如何将同一个文件复制两次?我正在尝试做这样的事情:

how can I copy two times the same file? I'm trying to do something like this:

                copy($file['tmp_name'], $folder."1.jpg");
            copy($file['tmp_name'], $folder."2.jpg");
            copy($file['tmp_name'], $folder."3.jpg");

临时文件在被服务器销毁之前有多少时间?

And how many time does temp files has before it's destroyed by the server?

我也尝试使用 move_uploaded_file,但我无法让它工作.我想从上传的文件中生成 2 个拇指.

I try using move_uploaded_file also, but I can't make it work. I want to generate 2 thumbs from an uploaded file.

需要帮助吗?

谢谢,

推荐答案

move_uploaded_file 将移动文件,而不是复制它——这意味着它只能工作一次.

move_uploaded_file will move the file, and not copy it -- which means it'll work only once.

如果你使用copy,应该没有任何限制完全取决于您可以复制的次数:上传创建的临时文件只会在脚本执行结束时被销毁(除非您之前移动/删除它,当然)


不过,也许解决方案是先使用 move_uploaded_file ,然后使用 copy ?
有点像,我想:


Still, maybe a solution would be to use move_uploaded_file first, and, then, copy ?
A bit like that, I suppose :

if (move_uploaded_file($file['tmp_name'], $folder . '1.jpg')) {
    copy($folder . '1.jpg', $folder . '2.jpg');
    copy($folder . '1.jpg', $folder . '3.jpg');
}

这将允许您获得 move_uploaded_file...

This would allow you to get the checks provided by move_uploaded_file...


如果这不起作用,那么请确保:


If this doesn't work, then, make sure that :

  • $folder 包含你想要的——包括最终的 /
  • 那个$file['tmp_name'] 也包含你想要的(我猜这是$_FILES 的某种副本——make确保 $_FILES$file 的副本正确完成)
  • $folder contains what you want -- including the final /
  • That $file['tmp_name'] also contains what you want (I'm guessing this is some kind of copy of $_FILES -- make sure the copy of $_FILES to $file is done properly)

这篇关于PHP:如何将上传的临时文件复制到多个地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)