0

I want to rename the file while uploading to avoid overwriting of files, I have following code, Please suggest code to avoid overwriting.

$path = "admin/uploads/resume/";
    if (!file_exists($path))
        mkdir($path, 0, true);
    $img_name = $_FILES['file']['name'];
    $img_tmp_name = $_FILES['file']['tmp_name'];
    $img_path = $img_name;
    move_uploaded_file($img_tmp_name, "admin/uploads/resume/" . $img_path);

    $img_name = $_FILES['file']['name'];
Sudarshan
  • 367
  • 2
  • 8
  • 20

1 Answers1

1

Try a time() with the file name. to avoid overwriting.

try this.

$img_name = time()."_".$_FILES['file']['name'];
Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59