我上传控制器上传图片。 file_view是我用来上传图片的html文件,upload_success是我用来检索文件的文件。在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.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);
}
}
}
?>
File_view
<?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>"?>
upload_success
<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;?>:
<?php echo $value;?>
</li>
<?php endforeach; ?>
</ul>
<p>
<?php echo anchor('upload_controller/file_view', 'Upload Another File!'); ?>
</p>
答案 0 :(得分:1)
试试这个:
<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>
答案 1 :(得分:0)
试试这个:
<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>
答案 2 :(得分:0)
只需执行此操作即可查看文件
<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!'); ?>
希望这对你有帮助。
答案 3 :(得分:0)
最后我找到了答案
<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>