問題描述
如何將同一個文件復(fù)制兩次?我正在嘗試做這樣的事情:
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");
臨時文件在被服務(wù)器銷毀之前有多少時間?
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
將移動文件,而不是復(fù)制它——這意味著它只能工作一次.
move_uploaded_file
will move the file, and not copy it -- which means it'll work only once.
如果你使用copy
,應(yīng)該沒有任何限制完全取決于您可以復(fù)制的次數(shù):上傳創(chuàng)建的臨時文件只會在腳本執(zhí)行結(jié)束時被銷毀(除非您之前移動/刪除它,當然)
不過,也許解決方案是先使用 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)
這篇關(guān)于PHP:如何將上傳的臨時文件復(fù)制到多個地方?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!