I cant figure out how to rename a filename inside the file upload script that I have.
Any help is really appreciated!!
Below is the script I am working on.
<?php
$target_dir = "../user_profile_pictures/";
$target_file = $target_dir . basename($_FILES["profile_pic"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
echo "Lo siento, el archivo ya existe.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "png") {
echo "Lo siento, solo se permiten imagenes tipo jpg, jpeg o png.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Lo siento, el imagen no se ha subido.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["profile_pic"]["tmp_name"], $target_file)) {
echo "El imagen ". basename( $_FILES["profile_pic"]["name"]). " se ha subido.";
} else {
echo "Ha habido un error al subir el archivo.";
}
}
?>