php 上傳一張照片 到兩個路徑?

$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);

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

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

阅读 2.6k
2 个回答

你第一次用move_uploaded_file之后,临时文件就不存在了,第二次就不能再执行了。

第一次移动后,第二个路径可以从第一个路径获取。

move_uploaded_file($_FILES["myFile_cover"]["tmp_name"], $destination);
file_put_contents($destination2,file_get_contents($destination));
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题