I use the UserFrosting user management system and I had problems downloading the file via the form message, thatβs what I tried
This is what my twig file looks like.
<form name="eveniment" method="post" action="{{form_action}}" enctype="multipart/form-data"> ... <input type="file" class="form-control" name="poza" id="poza"> ... </form>`
This is how my controller looks like
$target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["poza"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); // Check if image file is a actual image or fake image $check = getimagesize($_FILES); if($check !== false) { $ms->addMessage("success", "File is an image - " . $check["mime"] . "."); $uploadOk = 1; } else { $ms->addMessage("danger", "File is not an image."); $uploadOk = 0; } $ms->addMessage("success", $target_file); // Check if file already exists if (file_exists($target_file)) { $ms->addMessage("danger", "Sorry, file already exists."); $uploadOk = 0; } // Check file size if ($_FILES["poza"]["size"] > 500000) { $ms->addMessage("danger", "Sorry, your file is too large."); $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { $ms->addMessage("danger", "Sorry, your file was not uploaded."); // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["poza"]["name"], $target_file)) { $ms->addMessage("success", "The file ". basename( $_FILES["poza"]["name"]). " has been uploaded."); } else { $ms->addMessage("danger", "Sorry, there was an error uploading your file."); } }
Route
$app->post('/evenimente/?', function () use ($app) { $controller = new UF\EvenimentController($app); return $controller->createEveniment(); });
PHP configuration
file_uploads On
upload_max_filesize 128M
Each other input is sent successfully, except with type = "file".
I have no errors, I tried different methods, but to no avail. Also, if I type $_FILES["poza"]["name"] , it will be empty.
php file-upload twig slim userfrosting
Gerald hugs
source share