在codeigniter中检索图像
我有上传控制器上传图像。file_view是我用来上传图像的html文件,upload_success是我用来检索文件的文件。在上传成功文件中,输出如下所示在codeigniter中检索图像,codeigniter,Codeigniter,我有上传控制器上传图像。file_view是我用来上传图像的html文件,upload_success是我用来检索文件的文件。在上传成功文件中,输出如下所示 file_name: images.jpg file_type: image/jpeg file_path: C:/xampp/htdocs/Test/uploads/ full_path: C:/xampp/htdocs/Test/uploads/images.jpg raw_name: images orig_name: images.
file_name: images.jpg
file_type: image/jpeg
file_path: C:/xampp/htdocs/Test/uploads/
full_path: C:/xampp/htdocs/Test/uploads/images.jpg
raw_name: images
orig_name: images.jpg
client_name: images.jpg
file_ext: .jpg
file_size: 10.65
is_image: 1
image_width: 218
image_height: 232
image_type: jpeg
image_size_str: width="218" height="232"
有人能帮我用标签查看图像吗
控制器
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Upload_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index(){
$this->load->view('file_view', array(
'error' => ' '
));
}
public function file_view()
{
$this->load->view('file_view', array(
'error' => ' '
));
}
public function do_upload()
{
$config = array(
'upload_path' => "./uploads/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if ($this->upload->do_upload()) {
$data = array(
'upload_data' => $this->upload->data()
);
$this->load->view('upload_success', $data);
} else {
$error = array(
'error' => $this->upload->display_errors()
);
$this->load->view('file_view', $error);
}
}
}
?>
文件视图
<?php echo $error;?>
<!-- Error Message will show up here -->
<?php echo form_open_multipart( 'upload_controller/do_upload');?>
<?php echo "<input type='file' name='userfile' size='20' />"; ?>
<?php echo "<input type='submit' name='submit' value='upload' /> ";?>
<?php echo "</form>"?>
试试这个:
<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
<li>
<img src="<?php echo base_url('/uploads/').$upload_data['file_name'] ?>">
</li>
</ul>
<p>
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>
您的文件已成功上载!
-
">
只需执行此操作即可查看文件
<h3>Your file was successfully uploaded!</h3>
<img src="<?php echo upload_data['full_path']; ?>">
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
您的文件已成功上载!
">
希望这能对你有所帮助。试试这个:
<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li>
<?php echo $item;?>:
<img src="<?php echo $value;?>">
</li>
<?php endforeach; ?>
</ul>
<p>
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>
您的文件已成功上载!
-
:
">
我终于找到了答案
<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
<li>
</li>
<img alt="Your uploaded image" src="<?=base_url(). 'uploads/' . $upload_data['file_name'];?>">
</ul>
<p>
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>
您的文件已成功上载!
-
">
Riaz先生感谢您的帮助。但这也无法检索图像路径是否正确,但图像不预览谢谢您Akshay..但是上载数据应为$upload\u data是的,对于此代码。您可以更改变量名,但最终
<h3>Your file was successfully uploaded!</h3>
<!-- Uploaded file specification will show up here -->
<ul>
<li>
</li>
<img alt="Your uploaded image" src="<?=base_url(). 'uploads/' . $upload_data['file_name'];?>">
</ul>
<p>
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>