Home >>Advance PHP Tutorial >HomeHow to Rename image during upload

HomeHow to Rename image during upload

How to Rename image during upload


    if ($_POST['upload'] )





      $extension = explode("/", $_FILES["file"]["type"]);


    move_uploaded_file($tmp, "upload/" . $user.".".$extension[1]);

echo "Your file is uploaded with ".$user." name";     




     <form enctype="multipart/form-data" method="post">

    Your New file name<input type="text" name="c"/><br/>

    choose your file <input type="file" name="file"/><br/>

    <input type="submit" value="Upload" name="upload"/>




Output Your file is uploaded with phptpoint name your New file name choose your file
In the above example first enter your name whatever you want your new image name, second you have to get the extension of image using $_FILES['file']['type'] it returns the array. at the [0] index it shows image and at [1] index it shows your file extension like jpg, jpeg, png etc. now you have to put these new name like $user.".".$extension at the 2nd parameter of move_uploaded_file( ) function.

No Sidebar ads