0

I've almost taken this exactly as is from the CI docs, made some minor alterations to suit my needs but overall nothing significant. The folder I am attempting to upload to exists and has 777 set to its permissions.

The controller:

    if($this->input->post('uploads'))
    {
        $config['upload_path'] = realpath(APPPATH.'../images');
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = 0;
        $config['max_width']  = 0;
        $config['max_height']  = 0;
        $config['remove_spaces'] = true;

        $this->load->library('upload', $config);

        if (!$this->upload->do_upload())
        {
            $data['errors'] = $this->upload->display_errors();
        }
        else
        {
            $data['upload_data'] = $this->upload->data();
        }
    }

The View:

<?php
if(isset($errors))
{
    $this->genfunc->debugArray($errors);
}
if(isset($upload_data))
{
     $this->genfunc->debugArray($upload_data, 'php');
}
?>

<div id="gallery">
    <?php if (isset($images) && count($images)):
        foreach($images as $image): ?>
        <div class="thumb">
            <a href="<?php echo $image['url']; ?>">
                <img src="<?php echo $image['thumb_url']; ?>" />
            </a>                
        </div>
    <?php endforeach; else: ?>
        <div id="blank_gallery">Please Upload an Image</div>
    <?php endif; ?>
</div>

<div id="upload">
    <?php
    echo form_open_multipart('upload');
    echo form_upload('userfile');
    echo form_submit('uploads', 'Upload');
    echo form_close();
    ?>      
</div>

The view is loaded as well, everything currently gets sent back to the same page, which is expected. But having taken from the CI example in the Docs, and going over everything I see no reason why this shouldnt be working. Hoping someone can shed some light on it, maybe I am missing something?

4

3 回答 3

0

Apparently after all this futzin around. I changed

$this->load->library('upload', $config);

to

$this->load->library('upload'); $this->upload->initialize($upload_config);

While I was at it I changed my $config to $upload_config and that solved it. Not sure which was the conflict either using $config or just something flawed in the loading mechanism when the second param is passed. Either way. Uploads work now.

于 2012-09-30T05:22:01.003 回答
0

make sure you enable the debugging flag in the config file. Was facing the same issue and that got it solved. Also the directory in which the error log should be created in case of errors.

于 2012-09-30T05:24:59.533 回答
-1

Would initially try:

  1. Create an uploads directory off of your root site directory with 777 permissions
  2. update $config['upload_path'] = './uploads/';
于 2012-09-29T22:16:56.837 回答