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

[HELP] 上传类的路径一直找不到……帮忙一下吧

  [复制链接]
发表于 2010-3-15 12:40:24 | 显示全部楼层 |阅读模式
The upload path does not appear to be valid.
这句话就是一直以来的提示,我的uploads文件夹放在和system同一级的地方,然后路径设置中,用过
                $config['upload_path'] = './uploads/'
                $config['upload_path'] = getcwd().'.uploads/'
                $config['upload_path'] = base_url().'.uploads/'
均失败了,是我的路径写错了吗?还是要设置别的东西?
发表于 2010-3-15 13:03:44 | 显示全部楼层
本帖最后由 saturn 于 2010-3-15 13:06 编辑

想必你是在windows下做开发吧?用绝对路径就不用担心这些问题了。

PHP复制代码
$config['upload_path'] = FCPATH.'uploads/';
复制代码


FCPATH是index.php所在目录的绝对路径。
 楼主| 发表于 2010-3-15 13:39:58 | 显示全部楼层
回复 2# saturn


    谢谢,看来我不是错在这个地方了……改成绝对路径也提示不对,把代码全部贴上来,希望帮忙看看吧~
控制器:
<?php
class imageupload extends Controller {
        function __construct() {
                parent::Controller();
                $this->load->library('upload');
                $this->load->helper(array('form','url'));
        }
        function index() {
                $this->load->view('upload', array('error' => ' ' ));
        }

        function do_upload() {
                $config['upload_path'] = 'D:\wamp\www\test\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());
                        $this->load->view('upload', $error);
                }
                else
                {
                        $data = array('upload_data' => $this->upload->data());
                        $this->load->view('upload_success', $data);
                }
        }
}
?>

视图:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<?php echo form_open_multipart('imageupload/do_upload');?>
<input type="file" name="userfile" size="30" />
<br />
<br />
<input type="submit" value="upload" />
</form>
</body>
</html>
再次谢谢大家的帮忙了~
发表于 2010-3-15 13:51:40 | 显示全部楼层
var_dump(is_dir($config['upload_path']));

这类问题,不是路径写错了,就是权限问题,检查下吧,代码初步看了下,没啥问题。
 楼主| 发表于 2010-3-15 14:37:25 | 显示全部楼层
回复 4# saturn


    嗯,太好了,现在dump出来的结果是:
bool(true)
可是dump去掉以后,还是出现:
The upload path does not appear to be valid.
我在win下面,权限应该没问题吧~
 楼主| 发表于 2010-3-15 14:45:47 | 显示全部楼层
现在又在:
http://www.phpall.cn/forum/read.php?tid=142
载了一小段源码,是上传图片,然后生成缩略图的,记得上次载下来可以用的,这次却提示这个错误:
A problem was encountered while attempting to move the uploaded file to the final destination.
我在想是不是PHP环境配置的问题?我的GD2已经开启了……
发表于 2010-3-15 18:43:53 | 显示全部楼层
本帖最后由 saturn 于 2010-3-15 18:44 编辑

回复 6# ivanlw


PHP复制代码
/*
                 * Move the file to the final destination
                 * To deal with different server configurations
                 * we'll attempt to use copy() first.  If that fails
                 * we'll use move_uploaded_file().  One of the two should
                 * reliably work in most environments
                 */

                if ( ! @copy($this->file_temp, $this->upload_path.$this->file_name))
                {
                        if ( ! @move_uploaded_file($this->file_temp, $this->upload_path.$this->file_name))
                        {
                                 $this->set_error('upload_destination_error');
                                 return FALSE;
                        }
                }
复制代码


如果确定*权限没有问题*,那多半是服务器环境的问题。建议你下载一份新的CI框架代码,重新按照用户手册做一次,看有没有问题。

至于是不是和GD库有关系,你检查下是否的确生成了缩略图,如果没有,产生这个错误,也是可以理解的。
发表于 2010-3-15 23:15:43 | 显示全部楼层
好贴.顶一个













混乱战神
发表于 2010-3-16 11:40:30 | 显示全部楼层
echo realpath($config['upload_path']);
看看是哪里,如果空的说明物理路径不存在
发表于 2010-3-18 14:08:40 | 显示全部楼层
回复 1# ivanlw


    很明显你没有在index.php同级目录下建立uploads文件夹

本版积分规则