我想在 PHP 上的 Slim Framework V2 中使用 Dropzone JS。我无法到达 php 应该继续的控制器并将其移动到指定的文件夹。
这是我在树枝上的看法:
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Upload your files <br> <small>{{ datum.title}}</small></h1>
</div>
</div>
{#Dropzone part#}
<div class="row">
<div class="col-lg-12">
<form action="{{ urlFor('uploading.dropzone.post') }}" class="dropzone" id="myDrop">
{#CSRF#}
<input type="hidden" name="id" id="id" value="{{datum.id}}">
<input type="hidden" name="{{ csrf_key }}" value="{{ csrf_token }}"/>
{#End of CSRF#}
</form>
</div>
</div>
</div>
</div>
这是Javascript部分:
<script>
$(document).ready(function(){
var id = "{{ id }}";
Dropzone.options.myDrop = {
uploadMultiple: true,
maxFileSize: 2,
acceptedFiles: 'image/*',
init: function init(){
this.on('error', function(){
console.log('Error while uploading for data : '+id);
});
}
}
});
</script>
这是我的控制器
//Handle uploaded files in PHP and move them to the specified folder
$app->get('files/upload',$authenticateForRole('auth'),function ()use($app){
echo 'How did you get here?';
})->name('uploading.dropzone');
$app->post('files/upload/',$authenticateForRole('auth'),function()use($app){
$request = $app->request;
$id = $request->post('id');
if($id && is_numeric($id)){
//Definición inicial de variables
$root = getcwd();/*http://stackoverflow.com/a/28470557/1883256 - XAMPP on Windows*/
$directory = 'myFiles';
$sub_destination='/uploaded/dossiers/'.$directory;
$full_sub_dir=$root.$sub_destination;
$max_length = 215;/*url length*/
echo 'Posted! '.$id;
$file=$_FILES['file'];
//file properties:
$file_name=$file['name'];
$fileName_only=substr($file_name, 0, (strlen($file_name))-(strlen(strrchr($file_name, '.'))));/*http://stackoverflow.com/a/14204781/1883256*/
$file_tmp=$file['tmp_name'];
$file_size=$file['size'];
$file_error=$file['error'];
//working out the file extension:
$file_ext=explode('.',$file_name);
$file_ext=strtolower(end($file_ext));
$location=$full_sub_dir . '/' . $file_name;
move_uploaded_file($file_tmp, $location);
}else{
return $app->render('errors/400.twig');//bad request
}
})->name('uploading.dropzone.post');
这是我得到的错误。
状态码:404 未找到
我已经在这里解决了类似情况,但是对于 Dropzone,我无法让它工作:(
我错过了什么?我如何解决它?