【发布时间】:2019-10-23 06:13:02
【问题描述】:
我的代码工作正常,但现在不行,因为图像没有保存在文件夹中,我正在尝试将图像保存在存储文件夹中,以 id 作为图像名称。
控制器:
if($request->hasFile('profile_pic')){
if (Input::file('profile_pic')->isValid()) {
$file = Input::file('profile_pic');
$destination = 'storage/app/teachers'.'/';
$ext= $file->getClientOriginalExtension();
$mainFilename = $teacher->id.request()->$ext;
$file->move($destination, $mainFilename.".".'jpg');
echo "uploaded successfully";
}
查看:其中 0000 是默认图像。
<div class="row">
<a href="#"> <img id="imgFileUpload" name="profile_pic" src={{asset('storage/app/teachers/'.'0000'.'.jpg')}} value="{{@$teacher->id}}"
onerror="this.src='storage/app/teachers/0000.jpg';" data-toggle="tooltip" data-placement="top" title="click to upload image" class="profile_pic rspimg shadow-sm bg-white rounded" id="imgFileUpload" data-toggle="tooltip" data-placement="top" title="Click To Upload image"></a>
<div class=" col-md-10">
<input type="file" name="profile_pic" id="FileUpload1" style="display: none" />
<span id="spnFilePath"></span>
</div>
</div>
ajax: 在浏览器中预览图像。
<script>
$(document).ready(function(){
$(function () {
alert(2);
$("#FileUpload1").change(function () {
var imgControlName = "#imgFileUpload";
readURL(this, imgControlName);
});
function readURL(input, imgControlName) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$(imgControlName).attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
var fileupload = $("#FileUpload1");
var image = $("#imgFileUpload");
image.click(function () {
fileupload.click();
});
});
});
</script>
【问题讨论】:
-
错误是什么?
-
图像未存储。
-
您在上传图片时是否遇到任何错误?意味着你得到回声“上传成功”;作为回应?
-
我在屏幕上没有收到任何错误,只是没有保存。