* Het registreert de naam die je invult, maar doet verder hier niets mee
* Het registreert de klas die je selecteert uit een drop down menutje, maar doet hier verder niets mee
* Je kan een bestand vanaf de pc aanklikken, die wordt geupload als je op "inleveren" klikt.
Wat ik nu dus zou willen, maar (nog) niet snap, is hoe ik een bestand kan uploaden naar de map die wordt geselecteerd uit het dropdown menutje, en als prefix de naam die ingevuld staat.
Bijvoorbeeld: Klaas uit H5B levert het bestand "Presentatie.docx" in.
Hoe zorg ik (of beter gezegd, het script) er voor dat het bestand "Klaas - Presentatie.docx" in de map H5B terecht komt?
Hier een aantal stukken code die ik gebruik.
protected function checkName($file)
{
$this->newName = null;
$nospaces = str_replace(' ', '_', $file['name']);
if ($nospaces != $file['name']) {
$this->newName = $nospaces;
}
$nameparts = pathinfo($nospaces);
$extension = isset($nameparts['extension']) ? $nameparts['extension'] : '';
if (!$this->typeCheckingOn && !empty($this->suffix)) {
if (in_array($extension, $this->notTrusted) || empty($extension)) {
$this->newName = $nospaces . $this->suffix;
}
}
if ($this->renameDuplicates) {
$name = isset($this->newName) ? $this->newName : $file['name'];
$existing = scandir($this->destination);
if (in_array($name, $existing)) {
$i = 1;
do {
$this->newName = $nameparts['filename'] . '_' . $i++;
if (!empty($extension)) {
$this->newName .= ".$extension";
}
if (in_array($extension, $this->notTrusted)) {
$this->newName .= $this->suffix;
}
} while (in_array($this->newName, $existing));
}
}
}
protected function moveFile($file)
{
$filename = isset($this->newName) ? $this->newName : $file['name'];
$success = move_uploaded_file($file['tmp_name'], $this->destination . $filename);
if ($success) {
$result = $file['name'] . ' was succesvol geupload';
if (!is_null($this->newName)) {
$result .= ', en is hernoemd naar ' . $this->newName;
}
$result .= '.';
$this->messages[] = $result;
} else {
$this->messages[] = 'Kon het volgende bestand niet uploden: ' . $file['name'];
}
}
<h1>Bestanden uploaden</h1>
<?php if ($result || $error) {
?>
<ul class="result">
<?php
if ($error) {
echo "<li>{$error['message']}</li>";
}
if ($result) {
foreach ($result as $message) {
echo "<li>$message</li>";
}
}
?>
</ul>
<?php } ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<p>
<label for="username">Naam:</label>
<input type="text" name="name" id="" />
<br />
<label for="class">Klas:</label>
<select name="class">
<option value="h4a">h4a</option>
<option value="h4b">h4b</option>
<option value="h4c">h4c</option>
<option value="h5a">h5a</option>
<option value="h5b">h5b</option>
<option value="h5c">h5c</option>
</select>
<br />
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
<label for="filename">Selecteer bestand:</label>
<input type="file" name="filename[]" id="filename" multiple
data-maxfiles="<?php echo $_SESSION['maxfiles']; ?>"
data-postmax="<?php echo $_SESSION['postmax']; ?>"
data-displaymax="<?php echo $_SESSION['displaymax']; ?>">
</p>
<ul>
<li>
Er kunnen <?php echo $_SESSION['maxfiles']; ?> bestanden tegelijkertijd worden geupload.
</li>
<li>
Elk bestand mag niet groter zijn dan <?php echo UploadFile::convertFromBytes($max); ?>.
</li>
<li>
Samen mag het niet meer dan <?php echo $_SESSION['displaymax']; ?> zijn.
</li>
</ul>
<p>
<input type="submit" name="upload" value="Inleveren">
</p>
</form>
Ik kan de (complete) broncode wel in een PM zetten, maar zet deze liever niet helemaal openbaar.
Ik hoop dat iemand mij kan helpen!
PS:
For testing purposes: www.hofstadict.nl/inleveren2/form.php
