I want to upload a file from an input and rename it by the values of the inputs that the users provides but my script doesnt work and puts me these errors.
This is the HTML I am using:
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="inputGroupSelect01" name="selectionClasse">Classe</label>
</div>
<select class="custom-select" id="inputGroupSelect01">
<option selected disabled>Sélectionnez</option>
<option value="6e">Sixième</option>
<option value="5e">Cinquième</option>
<option value="4e">Quatrième</option>
<option value="3e">Troisième</option>
<option value="2nd">Seconde</option>
<option value="1e">Première</option>
<option value="term">Terminale</option>
</select>
</div>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for ="inputGroupSelect02">Matière</label>
</div>
<select class="custom-select" id="inputGroupSelect02" name="selctionMatiere">
<option selected disabled>Sélectionnez</option>
<option value="maths">Mathématiques</option>
<option value="frc">Français</option>
<option value="pc">Physique Chimie</option>
<option value="angl">Anglais</option>
<option value="svt">Sciences et Vie de la Terre</option>
<option value="latin">Latin</option>
<option value="esp">Espagnol</option>
</select>
</div>
<input id="datepicker" width="250" name="choixCalendrierDate">
<script>
$("#datepicker").datepicker({
uiLibrary: 'bootstrap4',
viewMode: 'years',
format: 'mm-yyyy',
});
</script>
This is the PHP script I am using to upload the files and rename them. The $nomfichier regroups all the values of the two options tags and the datepicker value. :
<?php
$folderDestination = '../uploads/img'; // ../ or ./ depends on your situation
$choixDeroulantClasse = isset($_POST['selectionClasse']);
$choixDeroulantMatiere = isset($_POST['selectionMatiere']);
$choixCalendrierDate = isset($_POST['choixCalendrierDate']);
$nomFichier = $choixDeroulantMatiere . $choixDeroulantClasse . $choixCalendrierDate;
if(isset($_POST['bouton']))
{
$choixDeroulantClasse = $_POST['selectionClasse'];
$choixDeroulantMatiere = $_POST['selectionMatiere'];
$choixCalendrierDate = $_POST['choixCalendrierDate'];
$nomFichier = $choixDeroulantMatiere . $choixDeroulantClasse . $choixCalendrierDate;
if(file_exists($folderDestination))
{
if(is_writable($folderDestination)) {
$files = array_filter($_FILES['files']['name']);
$totalFiles = count($_FILES['files']['name']);
$fileUploaded = array();
for($i=0;$i<$totalFiles;$i++)
{
$fileName = $_FILES['files']['name'][$i];
$ext = strtoupper(pathinfo($fileName, PATHINFO_EXTENSION));
$fileDestination = $folderDestination.'/'.$fileName;
if($ext == 'JPG' or $ext == 'PNG')
{
move_uploaded_file($_FILES['files']['tmp_name'][$i], $folderDestination.$nomFichier);
$fileUploaded[] = $fileName;
// do echo
echo $fileName.' uploaded <span style="color: green; font-weight: bold;">correctly</span>';
// or header action
header("Location: /submitfiled.php?info=uploadOK");
} else { echo '<span style="color: red; font-weight: bold;">'. $fileName .' uploaded error</span>'; }
}
} else { header("Location: /submitfail.php?info=folderNotExists"); }
} else { header("Location: /submitfail.php?info=folderIsNotWritable"); }
}
?>
I hope you can help me !