【发布时间】:2017-11-29 09:31:56
【问题描述】:
我想在文件夹中上传文件,以下是我在文件夹中上传文件的代码,该代码在我的本地系统中成功运行,并且文件也移动到了文件夹中,但在服务器端,当我使用 @987654322 时,我得到了 'The upload path does not appear to be valid'. @;但是当我使用$config['upload_path'] = './assets/images/store/category'; 时,我收到了成功消息,但上传的文件没有显示在category 文件夹中。
以下是我的代码。
控制器
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index() {
echo "Tst";
$this->load->view('Upload_form', array('error' => ' ' ));
}
public function Test_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('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('Upload_form', $error);
}
else {
$data = array('upload_data' => $this->upload->data());
echo '<pre>';
print_r($data);
// $this->load->view('upload_success', $data);
}
}
}
?>
视图(表单)
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('upload/Test_do_upload');?>
<input type = "file" name = "userfile" size = "20" />
<br /><br />
<input type = "submit" value = "upload" />
<?= form_close(); ?>
</body>
</html>
上传成功视图
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?phpforeach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?phpendforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>
代码在我的本地系统中运行,但在服务器端文件未移动到文件夹。我也同意了。
【问题讨论】:
-
在配置上传路径应该是 $config['upload_path'] = './assets/images/store/category/';并确保文件夹具有写入应用程序用户的权限
-
我在我的问题中提到,当我使用 $config['upload_path'] = './assets/images/store/category/';我收到了成功消息,但上传的文件没有显示在文件夹中,我也获得了许可。
-
你有两个表单标签在视图中
-
我删除了表单,但仍然没有显示上传的文件。
-
@samirsheikh 再次您不会通过助手关闭表单标签。你的
form_close()呢??
标签: php codeigniter