Php CodeIgniter:图像未上载。
gallery.php-查看Php CodeIgniter:图像未上载。,php,codeigniter,Php,Codeigniter,gallery.php-查看 <!DOCTYPE HTML> <html lang="en-US"> <head> <title>CI Gallery</title> </head> <body> <div id="upload"> <?php $this->load-&g
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<title>CI Gallery</title>
</head>
<body>
<div id="upload">
<?php
$this->load->helper("form");
echo form_open_multipart('gallery/up');
?>
<input type="file" name="file">
<?php
echo form_submit('upload','Upload');
echo form_close();
?>
</div>
</body>
</html>
CI画廊
gallery.php-controller
<?php
class Gallery extends CI_Controller {
function index()
{
$this->load->view('gallery');
}
function up()
{
$config['upload_path'] = './images/';
$config['allowed_types'] = 'gif|jpg|jpeg|png';
$config['max_size'] = '1000000';
$config['max_width'] = '10240';
$config['max_height'] = '7680';
$this->load->library('upload',$config);
$this->upload->do_upload('file');
$this->load->view('gallery');
}
}
在html中添加表单标记
<form enctype="multipart/form-data" name="" action=""></form>
您的代码看起来不错,没有错误。
尝试下面的代码来检查是否上传图像可能是路径问题?
复制下面的代码并放在上面
"$this->load->view('gallery');"
这是控制器的up功能
if (! $this->upload->do_upload())
{
$error = array('error' = $this->upload->display_errors());
// uploading failed. $error will holds the errors.
}
else
{
$data = array('upload_data' => $this->upload->data());
// uploading successfull, now do your further actions
}
您可以编写上传图像服务器端代码
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
print_r($error); //debug it here
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
问题是上传图像的文件夹没有写入权限,因此我将该文件夹设置为可写文件夹,现在可以正常工作。他有表单标签,它是表单打开\u多部分
?@BeatAlex,是的,但它不是建设性的