Ajax HTML5使用拖放上传文件
我想上传文件使用拖放 我使用的是LaravelFramework5.4和JS。问题在于上传完成后会发生什么。我可以看到该文件已上载到文件夹,但无法获取该文件的名称或任何引用 这是我的观点。。我正在上载文件以作为电子邮件附件发送Ajax HTML5使用拖放上传文件,ajax,file-upload,xmlhttprequest,session-variables,laravel-5.4,Ajax,File Upload,Xmlhttprequest,Session Variables,Laravel 5.4,我想上传文件使用拖放 我使用的是LaravelFramework5.4和JS。问题在于上传完成后会发生什么。我可以看到该文件已上载到文件夹,但无法获取该文件的名称或任何引用 这是我的观点。。我正在上载文件以作为电子邮件附件发送 {!! Form::open([ 'url' => 'send', 'files' => true, 'id'=>'upload', 'enctype'=> 'multipart/form-data' ]) !!}
{!! Form::open([
'url' => 'send',
'files' => true,
'id'=>'upload',
'enctype'=> 'multipart/form-data'
]) !!}
<div class="box-body">
<div class="form-group">
{!! Form::text('to', null, ['class' => 'form-control', 'placeholder' => 'Send to']) !!}
</div>
<div class="form-group">
{!! Form::text('subject', null, ['class' => 'form-control', 'placeholder' => 'Subject']) !!}
</div>
<div class="form-group">
{!! Form::textarea('content', null, ['class' => 'form-control message-body wysihtml5-sandbox', 'placeholder' => 'Message']) !!}
</div>
<div class="form-group">
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="320000" />
<div>
<label for="fileselect">Files to upload:</label>
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />
<div id="filedrag">or drop files here</div>
</div>
<div id="progress"></div>
<div id="messages">
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<div class="pull-right">
{{--<button class="btn btn-default"><i class="fa fa-pencil"></i> Draft</button>--}}
{!! Form::submit('Send', ['class' => 'btn btn-primary submit']) !!}
</div>
<div class="form-group">
<input type="hidden" id="MAX_FILE_SIZE" name="MAX_FILE_SIZE" value="320000" />
<div>
<label for="fileselect">Files to upload:</label>
<input type="file" id="fileselect" name="fileselect[]" multiple="multiple" />
<div id="filedrag">or drop files here</div>
</div>
<div id="progress"></div>
<div id="messages">
</div>
</div><!-- /.box-body -->
<div class="box-footer">
{!! Form::submit('Send', ['class' => 'btn btn-primary submit']) !!}
我试过了
Storage::put($fn, file_get_contents('php://input'));
$file = Storage::get($fn) ; return $file;);
public function send( Request $request ) {
$file = $this->getAttachments();
// $file = $false}
我想它返回false,因为如果我点击send,页面将刷新
而且$\u SERVER['HTTP\u X\u FILENAME']变量丢失,所以我尝试将其保存到会话中,但没有用。。无法获取文件
public function getAttachments()
{
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {
session(['attachments' => $fn]);
Storage::put($fn, file_get_contents('php://input'));
}
}
public function send( Request $request ) {
//Grab uploaded file
if ($request->session()->exists('attachments')) {
$attachments = $request->session()->pull('attachments');
$files = Storage::get($attachments);
}
不知道为什么,但它也不会存储到会话中。不确定您到底想做什么。但是如果你想通过拖放上传文件,我建议你使用这个很棒的js: 如果您想查看实现,可以在此处查看:
不确定你到底想做什么。但是如果你想通过拖放上传文件,我建议你使用这个很棒的js: 如果您想查看实现,可以在此处查看:
我无法让dropzone上传任何文件。它在前端工作,但我在尝试HTML5上传之前尝试过一次,现在当你建议它时,我在指定的文件夹中找不到该文件。我会仔细看一下它的选择,但现在我正试着这样做。这是我遵循的教程,如果它能帮助你更好地理解我不能让dropzone上传任何文件。它在前端工作,但我在尝试HTML5上传之前尝试过一次,现在当你建议它时,我在指定的文件夹中找不到该文件。我会仔细看一下它的选择,但现在我正试着这样做。这是我遵循的教程,如果它能帮助你更好地理解的话
Storage::put($fn, file_get_contents('php://input'));
$file = Storage::get($fn) ; return $file;);
public function send( Request $request ) {
$file = $this->getAttachments();
// $file = $false}
public function getAttachments()
{
$fn = (isset($_SERVER['HTTP_X_FILENAME']) ? $_SERVER['HTTP_X_FILENAME'] : false);
if ($fn) {
session(['attachments' => $fn]);
Storage::put($fn, file_get_contents('php://input'));
}
}
public function send( Request $request ) {
//Grab uploaded file
if ($request->session()->exists('attachments')) {
$attachments = $request->session()->pull('attachments');
$files = Storage::get($attachments);
}