I already search this question on internet and on this forum, but I don't see any answers for this.
The question is How to upload files with flightphp micro-framework with DropZonejs or others.
I have some code:
DropZone:
<form action="/admin/upload" method="put" class="dropzone">
<div class="fallback">
<input name="id" type="file" multiple />
</div>
PHP:
function upload() {
$uploaddir = $_SERVER['DOCUMENT_ROOT'] . '/tmp/';
$uploadfile = $uploaddir . '1.jpg';
//move_uploaded_file(json_encode(Flight::request()->getBody()), $uploadfile);
echo json_encode(file_put_contents($uploadfile, Flight::request()->getBody()));
}
Flight::route('POST /admin/upload', 'upload');
I used too this example, but have error with '$_FILES['userfile']':
function upload_admin() {
if(preg_match("/(gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG)$/", $_FILES['userfile']['name']))
{
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "OK";
}
}
}
Flight::route('/admin/upload', 'upload_admin');
After execute all of this operations I have the null result.
For example, I drag some file to DropZone. DZ request /admin/upload/. It's works, but in the end I have 1.jpg with null size.
Result of the uploading
Thanks to all.
UPD:Hmm, maybe it's problem in dropzonejs? I try some uploading php script without flightphp, and it doesn't upload files too with dropzone.
You can not get the files with getBody() method in Flight Framework. You can do it like
$file variable contains some properties as you know, when you var_dump() it.