Försöker göra om följande kod till MVC
Problemet är att i mitt formulär i vyn tar den emot en array name="user_files[]" och jag vet inte hur ska få den infromationen vidare till min controller och min modell.
Testat följande i min kontroller
Men gissar jag gör något fel med user_files[] i
Min modell ser ut så här vilket heller tydligen inte är rätt
Kod:
if (isset($_POST["sub"])) {
$msg = "";
if (count($_FILES["user_files"]) > 0) {
$folderName = "uploads/";
$counter = 0;
for ($i = 0; $i < count($_FILES["user_files"]["name"]); $i++) {
if ($_FILES["user_files"]["name"][$i] <> "") {
$ext = strtolower(end(explode(".", $_FILES["user_files"]["name"][$i])));
$filePath = $folderName . rand(10000, 990000) . '_' . time() . '.' . $ext;
if (!move_uploaded_file($_FILES["user_files"]["tmp_name"][$i], $filePath)) {
$msg .= "Failed to upload" . $_FILES["user_files"]["name"][$i] . ". <br>";
$counter++;
}
}
}
$msg = ($counter == 0) ? successMessage("Files uploaded Successfully") : errorMessage($msg);
} else {
$msg = errorMessage("You must upload atleast one file");
}
}
HTML-kod:
<form name="f" action="index.php" method="post" enctype="multipart/form-data">
<div style="width: 380px; margin: 0 auto;">
<fieldset>
<legend>Demo1</legend>
Attach multiple Files:
<input class="files" name="user_files[]" type="file" multiple="multiple" >
<div class="height10"></div>
<div><input type="submit" class="submit" name="sub" /> </div>
</fieldset>
</form>
Problemet är att i mitt formulär i vyn tar den emot en array name="user_files[]" och jag vet inte hur ska få den infromationen vidare till min controller och min modell.
Testat följande i min kontroller
Kod:
public function uploadImages() {
if (isset($_POST["submit_file_upload"]) && $_SERVER["REQUEST_METHOD"] == "POST") {
$this->model->imageUpload($_POST["user_files[]"]);
}
}
Men gissar jag gör något fel med user_files[] i
Kod:
$this->model->imageUpload($_POST["user_files[]"]);
Min modell ser ut så här vilket heller tydligen inte är rätt
Kod:
public function imageUpload(user_files[])
{
//code
}