我想基于我的 public function uploadImages(Request $request, $applications_id)
{
$applications = new Applications;
// $KRAPIN = Input::get('KRA_unique_field');
$applications_id = Input::get('applications_id_unique_field');
if ($request->hasFile('breg_cert')) {
if ($request->file('breg_cert')->isValid()) {
// request()->breg_cert->move(public_path('breg_cert'), $imgName);
// $imgName = basename($request->breg_cert->store(public_path('breg_cert')));
$imgName = basename($request->breg_cert->move(public_path('breg_cert')));
$applications->breg_cert = $imgName;
}
return response()->json(['uploaded' => '/breg_cert/'.$imgName]);
}
}
来获取文件,并且希望在引导文件输入中看到该文件,并且希望将其删除并替换为新文件。我该怎么做。以下是我尝试过的方法。任何人都可以帮助我。我被困住了。
这是我的contoller函数SoleProprietorController.php
Route::post('/uploadImages/{applications_id}', 'SoleProprietorController@uploadImages')->name('home');
这是我的web.php
<div class="col-md-4 mb-3">
<label for="validationServer023">Upload Business Registration Document</label>
<div class="form-group">
<div content="{{ csrf_token() }}" class="input-group input-file" name="Fichier1">
<input id="file-0a" name="breg_cert" value="" class="file" accept="text" type="file"> <br />
</div>
</div>
</div>
<script>
$("#file-0a").fileinput({
initialPreview: [
"<img src='/images/php' class='file-preview-image'>",
],
showUpload: true,
showRemove: true,
showCaption: true,
showPreview: true,
showClose: false,
autoOrientImage: true,
showUploadedThumbs: false,
uploadAsync: false,
uploadUrlThumb: false,
deleteUrl: "/public/KFS_Business_Registration_Certificates",
uploadUrl: "/uploadImages/{applications_id}",
// dataUrl: "/breg_cert/",
// uploadUrl: '/public/KFS_Business_Registration_Certificates', // you must set a valid URL here else you will get an error
theme: 'fa',
uploadExtraData: function() {
return {
_token: "{{ csrf_token() }}",
};
},
allowedFileExtensions: ['jpg', 'png', 'gif', 'pdf', 'jpeg'],
overwriteInitial: false,
maxFileSize: 500,
maxFilesNum: 10,
//allowedFileTypes: ['image', 'video', 'flash'],
slugCallback: function (filename) {
return filename.replace('(', '_').replace(']', '_');
}
});
</script>
这是我刀片中的引导文件
<table>
<tr>
<th>Employee </th>
<th>Skills</th>
</tr>
<% @employees.each do |employee|%>
<tr>
<td><%= employee.name %></td>
<td><%= employee.skills.map(&:name).join(', ') %></td>
</tr>
<% end %>
</table>
答案 0 :(得分:0)
1。使用这样的代码存储上传的文件并将其与您的应用程序关联
if ($request->hasFile('breg_cert')) {
if ($request->file('breg_cert')->isValid()) {
$imgName = basename($request->breg_cert->store(public_path('breg_cert')));
$applications->breg_cert = $imgName;
}
}
https://laravel.com/docs/5.8/requests#storing-uploaded-files
要存储上载的文件,通常将使用已配置的文件系统之一。 UploadedFile类具有一个store方法,该方法会将上载的文件移动到您的一个磁盘上,该磁盘可以是本地文件系统上的某个位置,甚至可以是Amazon S3之类的云存储位置。
store方法接受相对于文件系统配置的根目录应存储文件的路径。该路径不应包含文件名,因为会自动生成一个唯一的ID作为文件名。
在上述方法中,检查关联的文件名并取消链接。 (实际代码取决于dd($request);
的输出内容)
initialPreview: [
"<img src='/images/path-to.jpg' class='file-preview-image'>",
],