Good afternoon.
I want to upload a file to my server but it will be renamed with the name of a variable that comes by method GET
, that is, the address would be localhost/fotos/subir.php?nuevonombre=juan
, and if the file is called Felipe.jpg
, I want it to be renamed and it's called juan.jpg
.
Here I attach the code
<!DOCTYPE html>
<html lang="es">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Subir archivos al servidor</title>
<meta name ="author" content ="Norfi Carrodeguas">
<style type="text/css" media="screen">
body{font-size:1.2em;}
</style>
</head>
<body>
<form enctype='multipart/form-data' action='' method='post'>
<input name='uploadedfile' type='file'><br>
<input type='submit' value='Subir archivo'>
</form>
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "<span style='color:green;'>El archivo ". basename(
$_FILES['uploadedfile']['name']). " ha sido subido</span><br>";
}else{
echo "Ha ocurrido un error, trate de nuevo!";
}
?>
</body>
</html>
Thank you very much.