开发者

The upload destination folder does not appear to be writable. (Codeigniter)

I have two upload scripts that do very similar functions just with different directories.

function town_upload() {


        //Do not create a thumbnail
        $create_thumb = false;

        //Create the path for the upload
        $path = './public/uploads/towns/' . $this->uri->segment(3);

        $config['upload_path'] = $path;
        $config['allowed_types'] = 'jpg';
        $config['max_size'] = '2048';
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
        $config['remove_spaces'] = TRUE;
        $config['overwrite'] = $this-&开发者_运维技巧gt;image_upload_overwrite;

        if ($this->input->post('image_type') == 'main_image') {
            $config['file_name'] = 'main.jpg';
            $create_thumb = true;
        } 

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

        if (!$this->upload->do_upload()) {

            $this->session->set_flashdata('upload_error', array('error' => $this->upload->display_errors()));

        } else {

            //sucess so now we create the thumbnail
            $this->session->set_flashdata('upload_success', $this->upload->data());

Example: If I had a town with the ID of 6, the upload directory would be public/uploads/towns/6. This works perfectly fine as the directory is created when the town is created. I have nearly the exact same function for hotels except the path is public/uploads/hotels/[ID]. I have set the permissions to 777 just to remove that from the equation for now.

I cannot figure this out as they are both very similar functions. Here is the hotel upload code:

 function hotel_upload() {

        //Create the path for the upload
        $path = './public/uploads/hotels/' . $this->uri->segment(3);

        chmod($path, 0777);

        $config['upload_path'] = $path;
        $config['allowed_types'] = 'jpg';
        $config['max_size'] = '2048'; //kilobytes (2048 = 2mb)
        $config['max_width'] = '1024';
        $config['max_height'] = '768';
        $config['remove_spaces'] = TRUE;
        $config['overwrite'] = TRUE;

        if ($this->input->post('image_type') == 'main_image') {
            $config['file_name'] = 'main.jpg';
        }

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

        if (!$this->upload->do_upload()) {

            $this->session->set_flashdata('upload_error', array('error' => $this->upload->display_errors() . ' <br/>Path: ' . $path . '<br/>Image Type: ' . $this->input->post('image_type')));

        } else {

            //sucess so now we create the thumbnail
            $this->session->set_flashdata('upload_success', $this->upload->data());

The hotel function gives me the error "The upload destination folder does not appear to be writable.".

Here are the pages HTML forms:

TOWN:

<?php echo form_open_multipart('admin/town_upload/' . $this->uri->segment(3));?>

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

            <br /><br />

            <p>
                <input type="radio" name="image_type" checked="checked" class="radio" value="main_image" /> <label>Main Image</label>
                <input type="radio" name="image_type" class="radio" value="other_image" /> <label>Other Image</label>
            </p>

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

        <?php echo form_close(); ?> 

HOTEL:

<?php echo form_open_multipart('admin/hotel_upload/' . $this->uri->segment(3));?>

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

            <br /><br />

            <p>
                <input type="radio" name="image_type" checked="checked" class="radio" value="main_image" /> <label>Main Image (shown when visitors search the website)</label>
                <input type="radio" name="image_type" class="radio" value="other_image" /> <label>Standard Image</label>
            </p>

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

        <?php echo form_close(); ?> 

Thanks in advance! Been working on this for hours now.. :(


Your code doesnt check the chmod works. For example, by default, apache loves to run as its own user or nobody, not you as a user. So, the chmod in your file may find the user its currently running as doesnt own the file, so the chmod fails.

First thing I would check would be the user PHP thinks it runs as, and the owner of the file.

There is the is_writable function, you could check the directory is writable.


I just ran into the same problem and found a possible reason for this behaviour. In my case, I had created the upload directory a while back. I upgraded php which put in a new php.ini file that had safe_mod = On. And now when I recreated the directory after erasing it, the new php parameters kicked in throwing this error message.

Could it just be possible that you created the town dir tree before a PHP upgrade and your hotel dir tree afterwards?


Okay, just came back to this. I think permissions got messed up somewhere, I destroyed and recreated the folder and it seemed to work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜