在网页上传图片无法在下一个确认页面显示问题
部分代码如下:
<form action="<?= $action; ?>" id="groupevent_registration" method="post" novalidate autocomplete="off" enctype="multipart/form-data">
<input type="file" id="image_file" accept="image/jpg, image/jpeg, image/png" value="" name="image_file">
//这里显示
<?php if ($image !== '') : ?>
<img src="<?= $image; ?>">
<?php endif; ?>
public function registration() {
$presenter = \Presenter::forge('groupevent/groupevent', 'registration', true, 'groupevent/registration');
$post_data = \Input::post();
if (!empty($post_data)) {
\Session::set('groupevent_register_post_data', $post_data);
\Response::redirect('groupevent/groupevent/confirm');
}
public function confirm() {
$fieldset = \Fieldset_Factory::create('groupevent_confirm');
$post_data = \Session::get('groupevent_register_post_data');
$this->set('post_data', $post_data);
$image = Session::get('groupevent_base64_images', null);
if ($image) {
$binary = Util_File::data_uri_scheme_to_binary($image['image_file']);
$extension = Util_File::get_extension($binary);
if ($extension === '.jpg') {
$binary = Util_Image::fix_orientation_from_binary($binary);
$image['image_file'] = Util_File::binary_to_data_uri_scheme($binary, 'image/jpeg');
}
}
$this->set_safe('image', $image['image_file'] ?? '');
}
省略了其他的处理留下了图片相关,可以从第一个页面的input中取得所有的post_data,但是在确认页面中dump"image"变量为空,
难道是在上传图片进行页面跳转的时候就没有图片信息被传递? 目前不知道原因在哪里,还请教可能出现错误的地方等等,谢谢
用的什么框架了?一般Input::post只是获取post提交中的键值对,不包含文件。文件应该用类似Input::file获取,参考
看下加载的图片资源地址是什么
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!根据问题描述,可能出现错误的地方是在上传图片后进行页面跳转时,未能正确传递图片信息。解决这个问题的方法是在上传图片时,将图片信息保存到某个地方(例如服务器或者本地存储),然后在确认页面中从该地方获取图片信息进行显示。
下面是具体的解决方案:
wx.uploadFile({
url: '图片上传地址',
filePath: '选择的本地图片路径',
name: '图片字段名称',
success: function(res) {
// 保存上传的图片信息到某个地方(例如数据库或文件系统)
// 可以将图片的URL保存到数据库,以便后续通过URL获取图片
}
});
wx.request({
url: '获取图片URL的接口地址',
method: 'GET',
data: {
// 根据需要传递的参数(例如图片ID)进行设置
},
success: function(res) {
// 将获取到的图片URL保存到image变量中
var image = res.data.image;
// 将image变量的值传递给确认页面进行显示
// 可以通过setData方法将image值保存到确认页面的data中
// 例如:this.setData({ image: image });
}
});
<image src="{{image}}" alt="" style="width:300rpx; height:300rpx"/>
通过以上的解决方案,可以实现在确认页面中显示上传的图片。