用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2765|回复: 3
收起左侧

[HELP] 老问题,上传类的路径问题,求助

[复制链接]
发表于 2011-3-23 19:26:15 | 显示全部楼层 |阅读模式
controller中的upload.php代码如下:
<?php

class Upload extends CI_Controller {

function __construct()
{
  parent::__construct();
  $this->load->helper(array('form', 'url'));
}

function index()
{
  $this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
  $config['upload_path'] ='./upload/';
  //$config['upload_path'] = base_url().'upload/';
  //$config['upload_path'] = getcwd().'./upload/';  
  $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());

   $this->load->view('upload_form', $error);
  }
  else
  {
   $data = array('upload_data' => $this->upload->data());

   $this->load->view('upload_success', $data);
  }
}
}
?>

view中upload.form的代码如下:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<?php echo $error;?>

<?php echo form_open_multipart('upload/do_upload');?>

<input type="file" name="userfile" size="20" />

<br /><br />

<input type="submit" value="upload" />

</form>

</body>
</html>

另外在upload_success.php中的代码如下:
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<h3>Your file was successfully uploaded!</h3>

<ul>
<?php foreach($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>

</body>
</html>



错误提示:
The upload path does not appear to be valid.

我改成:
        $config['upload_path'] = base_url().'upload/';
           $config['upload_path'] = getcwd().'./upload/';        
还是会报错,奇怪的是例外装个ci按上面的代码测试是成功~~~

不知道原因是什么??
 楼主| 发表于 2011-3-23 19:27:12 | 显示全部楼层
$config['base_url']        = 'http://localhost/ci/';
和在根目录下建立了个upload文件夹,也重写了这个文件夹,结果还是不行
发表于 2011-3-23 20:11:07 | 显示全部楼层
  1. 你还需要一个目标文件夹来存储上传的图片。在根目录上创建一个名为uploads的文件并设置该文件的属性为 777。(即可读写)
复制代码
 楼主| 发表于 2011-3-23 20:58:22 | 显示全部楼层
我在另一个ci里面完全一样的代码,和根目录下建立个upload文件,是可以上传的!!

本版积分规则