简体   繁体   English

在重定向时将文件附加到表单

[英]Attach file to form on redirect

Im providing a file preview option, where the user attaches a file, and then clicks preview. 我提供了文件预览选项,用户可以在其中附加文件,然后单击预览。 Which uploads the file, and outputs a PHPExcel preview. 上载文件,并输出PHPExcel预览。

From that page, I want to include a button that says continue. 在该页面上,我想包含一个继续按钮。 Which will then proceed with the actual upload and database row creation. 然后将继续进行实际的上载和数据库行的创建。

However once I redirect to the preview page, I have no idea how to attach this file to my hidden form for resubmission. 但是,一旦我重定向到预览页面,我就不知道如何将此文件附加到我的隐藏表单中以重新提交。

I can attach all the old input values....like so... But how do I attach the file??? 我可以附加所有旧的输入值...。像这样...但是如何附加文件??? (using blade in laravel for templating) (使用laravel中的刀片进行模板制作)

/* These work and are correct*/
<input type="text" id="xlsColumnOrder" name="xlsColumnOrder" value="{{$input['xlsColumnOrder']}}"/>
<input type="text" name="researcher" value="{{$input['researcher']}}" />    
<input type="text" name="leadcity" value="{{$input['leadcity']}}" />
<input size="16" id="survey_date" name="survey_date" type="text" value="{{$input['survey_date']}}"  /> 
/* This doesnt attach anything to the file input
/*  Need to attach the previously uploaded file here for resubmission */                                 
<input class="file" id="csvfile" name="csvfile" type="file" value="{{$file['csvfile']['tmp_name']}}" />

You cannot automatically resend user files so I would do it this way: 您无法自动重新发送用户文件,因此我可以这样进行:

  • When user sends form if any file is provided you save file in some directory (you treat it as temporary) and save file name/names to session and show user preview of file 当用户发送表单时,如果提供了任何文件,则将文件保存在某个目录中(将其视为临时文件),并将文件名保存到会话中,并显示文件的用户预览
  • When he clicks continue - you can do with other data whatever you want (for example save it to database or show as hidden in another form) and you still have uploaded filename in session so if you want you may even again show file preview 当他单击继续时,您可以随意处理其他数据(例如,将其保存到数据库中或以其他形式显示为隐藏),并且您仍在会话中上传了文件名,因此如果您愿意,甚至可以再次显示文件预览
  • When you want to finally save all user data you move user file/files to final directory (and possible rename it) and save all the data with file(s) name (probably in database). 当您要最终保存所有用户数据时,可以将一个或多个用户文件移动到最终目录(并可能将其重命名),然后将所有数据保存为文件名(可能在数据库中)。

As addition you should have some kind of cron that removes data from your temporary directory that very created for example more than 3 hours 另外,您应该具有某种cron来从您的临时目录中删除数据,而该临时目录的创建时间非常长,例如3个小时

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM