Good morning people, i've been trying to solve this for some days, but i must admit im kind of new on this of programming.

Actually im making a news website, and for the news management im having a small problem, i want that, when i click to save the pic it get's a random name, not the one it had from the user files, e.x: pic.jpg saves as 2613.jpg.

Im trying to do this to prevent that if there are 2 pics with same name the new one replace the old one, ive tried with javascript, php and yet i wouldnt be able to solve my problem, hope you guys may help me, by the way, im working using javascript, php, postgresql, jquery and ajax, if you need more details please let me know, and, once again, hope i can get some help from this community.

```
function guardar(){
if($('#titl').val() == '' || $('#categ').val() == '' || $('#cont').val()==''){
            alert("Todos los campos deben contener datos!");
            return false;
        }

        $.ajax({
            url: "noticias_php.php",
            data:{
                n : rand(),
                "accion" : "guardar",
                ID     : $('#id').val(),
                Titulo : $('#titl').val(),
                Categorias : $('#categ').val(),
                Contenido : $('#cont').val(),
                fecha: $('#fecha').val(),
                imagen: $('#img_id').val()

            },
            success: function(datos){
                var respuesta = explode("-*", datos);

                        if (respuesta[0] == "SI"){
                            aviso(respuesta[1]);
                            limpiar();
                        }else if (respuesta[0] == "NO"){
                            aviso(respuesta[1]);
                        }else{
                            aviso(datos);
                        }
            }
        });
    }

```