我使用dropzone.js脚本在Laravel框架中上传图片,上传图片后一切正常,但我无法在提交按钮后移动到文件夹。
我正在阅读文档,论坛,以及为将代码添加到dropzone.js文件而编写的所有内容 但它仍然不起作用,它只是在上传后立即移动图像
我想这样做只有在点击提交按钮后图像才会移动到给定路径。不是在它过了之后。
Dropzone.js
function __guardMethod__(obj, methodName, transform) {
if (typeof obj !== 'undefined' && obj !== null && typeof obj[methodName] === 'function') {
return transform(obj, methodName);
} else {
return undefined;
}
};
/*
Code below is that I need to add
*/
Dropzone.options.myDropzone = {
// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,
init: function() {
var submitButton = document.querySelector("#submit-all")
myDropzone = this; // closure
submitButton.addEventListener("click", function() {
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
});
// You might want to show the submit button only when
// files are dropped here:
this.on("addedfile", function() {
// Show submit button here and/or inform user to click it.
});
}
};
PHP表格
</head>
<body>
<h3>Image upload</h3>
{!! Form::open(array('url'=>'imgUpload', 'method' => 'PUT',
'name'=>'product_images', 'id'=>'myImageDropzone', 'class'=>'dropzone', 'files'=>true )) !!}
<input type="button" name="submit" id="submit-all" value="Click Me">
{!! Form::close() !!}
</body>
<script type="text/javascript" src="\js\dropzone.js"></script>
</html>
imageController,我试图添加isset但仍然是同样的问题。
class imageController extends Controller
{
public function index(){
return view('imgUpload');
}
public function uploadFiles(Request $request){
if (isset($_POST["submit"]))
{
if ($request->hasFile('file'))
{
$imageFile = $request->file('file');
$imageName = uniqid().$imageFile->getClientOriginalName();
$imageFile->move(public_path('uploads'),$imageName);
}
}
return view('imgUpload');
}
}