how to send a file with the same name without replacing in php

Asked

Viewed 16 times

0

<?php
$dir = "arquivo";
$file = $_FILES["csv1"];
if (file_exists('arquivo/dados.csv')) {
    echo "Um arquivo já foi enviado! Envie outro arquivo!";
    exit;
} else {

    if (move_uploaded_file($file["tmp_name"], "{$dir}/dados.csv")) {
        echo "Arquivo enviado com sucesso!";
    } else {
        echo "Erro, o arquivo não pode ser enviado.";
    }
}
  • how do I do it? type if add another it overwrites does not add a new file

  • "{$dir}/dados.csv" will be the name of the file you save to the server. Simply change the value of dados.csv

  • but I want to add two csv files with same name sera that have as ?

  • I didn’t understand those ways as you would ?

  • In these ways, generating a unique name for each file sent...

  • edits the code for me to see how you would do is that I don’t know much of php kk

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.