I would like to change a pictures name while uploading it.
Here is my code:
if(isset($_POST['submit']))
{
$target_dir = "pictures/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Allow certain file formats
if($imageFileType != "gif" ) {
echo "Sorry only GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
header('Location:field_medal_winner.php');
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
First I tried to do it whith changing the move_uploaded_file function. But I just got the else message:
if (move_uploaded_file("text.gif", $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
Does anyone have an Idea what I am doing wrong?