-1

第一次使用,My PHP 目前处于业余假期。但是,我正在创建一个基本网站(对于汽车公司),管理员用户需要添加图片。我目前的代码是

'echo "NEW RECORD CREATED" . "<br>";
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
   }
} } else { echo "Invalid file"; }}'
4

1 回答 1

4

You just need to update this part of your code ... it will add a unique ID to the front of the file name.

move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . uniqid() . "_" . $_FILES["file"]["name"]);
于 2013-10-28T15:48:53.280 回答