I'm trying to rename the uploaded file by adding the uploader name($user) but all it does is showing user's name in the extension part, file.jpguser, here's the code,
if ((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
//Check if the file is JPEG image and it's size is less than 1.4MB
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 10485760))
{
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/affichagesimg/'.$filename'by'.$user;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
echo "<script>
alert('votre affichage a était publié avec succés !');
window.location.href='.';
</script>";