鍍金池/ 問(wèn)答/PHP  網(wǎng)絡(luò)安全/ php 上傳一張照片 到兩個(gè)路徑?

php 上傳一張照片 到兩個(gè)路徑?

$target_dir = "a1/";
  $target_file = $target_dir . basename($_FILES["myFile_cover"]["name"]);
  $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  $imagename = $addfirstROW['id'] . '.' . $imageFileType;
  $destination = $target_dir . $imagename;
  $destination2 = "a2/" . $imagename;
move_uploaded_file($_FILES["myFile_cover"]["tmp_name"], $destination);
  move_uploaded_file($_FILES["myFile_cover"]["tmp_name"], $destination2);

我想同一照片上傳到不同的路徑...
一個(gè)是a1一個(gè)是a2
都是同一張照片
這要怎麼做?就是變兩張的意思

上傳照片後我會(huì)先把圖片壓縮,再存到a1,但我想有個(gè)原始檔(未壓縮的)先到a2備份

回答
編輯回答
短嘆

copy

2017年2月6日 18:44
編輯回答
雨蝶

你第一次用move_uploaded_file之后,臨時(shí)文件就不存在了,第二次就不能再執(zhí)行了。

第一次移動(dòng)后,第二個(gè)路徑可以從第一個(gè)路徑獲取。

move_uploaded_file($_FILES["myFile_cover"]["tmp_name"], $destination);
file_put_contents($destination2,file_get_contents($destination));
2017年10月26日 19:25