When an image is uploaded to the server, it is copied to the folder where the download handler itself is located, in addition to moving to the persistent folder. Tell me how to level this effect. Code related to downloading a file:

$uploaddir = '../images/uploads/directors/'; $uploadfile = $uploaddir . basename($_FILES['photo']['name']); $photoname = 'dir_photo_' . date('U') . '.' . pathinfo($uploadfile, PATHINFO_EXTENSION); if (!is_dir($uploaddir)) { mkdir($uploaddir, 0777, true); } if (!move_uploaded_file($_FILES['photo']['tmp_name'], $uploadfile)) { mysqli_close($db); die ('Файл не был загружен'); } if (!rename($uploadfile, $photoname)) { mysqli_close($db); die ('Ошибка переименования файла'); } 
  • one
    In this piece of code there is no copying, there is only moving the file. Perhaps the file cannot be moved and then it remains in the folder with the handler. You can try to combine move_uploaded_file and rename - they have the same role to move the file. You do not need to move it 2 times. - Oboroten
  • Thanks It works! - emptybottle
  • I duplicated below as the answer. Please mark my answer as correct. - Oboroten

1 answer 1

In this piece of code there is no copying, there is only moving the file. Perhaps the file cannot be moved and then it remains in the folder with the handler. You can try to combine move_uploaded_file and rename - they have the same role to move the file. You do not need to move it 2 times.