PHP:如何将临时文件上传复制到多个地方? [英] PHP: how do I copy a temp file upload to multiple places?
问题描述
$ $ p $ $ codeopy $($ file ['tmp_name'],$ folder。 JPG);
copy($ file ['tmp_name'],$ folder。2.jpg);
copy($ file ['tmp_name'],$ folder。3.jpg);
临时文件在被服务器销毁之前已经有多少次了?
我也尝试使用move_uploaded_file,但是我无法使它工作。我想从上传的文件中生成2个大拇指。
有些帮助吗?
感谢,
move_uploaded_file
将移动文件,而不是复制它 - 这意味着它只能工作一次。
如果您使用 copy
,复制次数不应该有任何限制:由上传创建的临时文件只会在脚本执行结束时被销毁(当然,除非您之前移动/删除它)
另外,也许一个解决方案是首先使用 move_uploaded_file
,然后
有点像,我想:
if(move_uploaded_file($ file ['tmp_name'] ,$ folder。'1.jpg')){
copy($ folder。'1.jpg',$ folder。'2.jpg');
copy($ folder。'1.jpg',$ folder。'3.jpg');
$ b $ p
$ b 这将允许你得到 move_uploaded_file
...
如果这不起作用,请确保:
$ b
-
$文件夹
包含您想要的内容 - 包括最后的 /
-
$ file ['tmp_name']
也包含你想要的东西猜测这是 $ _ FILES
的副本 - 确保 $ _ FILES
的副本为 $ file
正确完成)
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?
I try using move_uploaded_file also, but I can't make it work. I want to generate 2 thumbs from an uploaded file.
Some help?
Thanks,
解决方案 move_uploaded_file
will move the file, and not copy it -- which means it'll work only once.
If you are using copy
, there shouldn't be any limit at all on the number of times you can copy : the temporay file created by the upload will only be destroyed at the end of the execution of your script (unless you move/delete it before, of course)
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');
}
This would allow you to get the checks provided by move_uploaded_file
...
If this doesn't work, then, make sure that :
$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:如何将临时文件上传复制到多个地方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!