我上传了一张图片,然后对图片进行了旋转操作,并在其他视图中获取了翻转的图片,现在如何下载翻转的图片请指导我?
上传图像的查看代码:
<input type='file' name="userfile" size="20">
<input type="submit" name="upload" value="Flip">
翻转控制器代码:
$data['title'] ='Flip Image';
$upload['upload_path'] = './assets/images/';
$upload['allowed_types'] = 'gif|jpg|jpeg|png';
$this->load->library('upload',$upload);
$filedata1 = $this->upload->data();
if(!$this->upload->do_upload('userfile')){
show_error($this->upload->display_errors());
}
$this->load->library('image_lib');
$config['image_library'] = 'gd2';
$config['source_image'] = $this->upload->data('full_path');
$config['rotation_angle'] ='hor';
$this->image_lib->initialize($config);
if(!$this->image_lib->rotate()){
show_error($this->image_lib->display_errors());
}
$filedata = $this->upload->data();
$data['img2'] = base_url().'/assets/images/'.$filedata['file_name'];
print $this->load->view('pages/result',$data,true);
下载功能:
$this->load->helper('download');
$data = 'myimag.png';
force_download($img2, $data);
redirect('pages/result');
现在我正在其他页面中获取这个图像结果,在这里我调用了控制器的下载功能(如上所述(,点击下载按钮,它应该开始下载文件,而无需询问路径,但它显示错误:结果视图:
<img src="<?php echo $img2;?>" width="200" height="200">
<?php echo form_open('pages/download()'); ?>
<input type="submit" name="submit" value="Download">
</form>
错误:函数Pages:download((的参数太少,传入了0D: 第532行的\axamp\htdocs\ImageTools\system\core\CodeIgniter.php和恰好1个预期
希望这将帮助您:
你可以这样做:
注意:确保此处$img2
包含图像文件的完整路径
<img src="<?php echo $img2;?>" width="200" height="200">
<a href="<?php echo $img2;?>" download="myimage" >Download</a>
或者简单地这样做:
<img src="<?php echo $img2;?>" width="200" height="200">
<a href="<?=base_url('pages/download/'.$img2);?>" >Download</a>
你的download
方法应该是这样的:
function download($img2)
{
$this->load->helper('download');
/*make sure here $img2 contains full path of image file*/
force_download($img2, NULL);
}
更多信息:https://www.w3schools.com/tags/att_a_download.asp