Welcome Guest, Not a member yet? Register   Sign In
Uploading Class do_upload() works intermittently
#1

[eluser]Shaun Andrews[/eluser]
Hi All,

I'm working on a way to allow image uploads, but it only seems to work intermittently; sometimes files upload fine, sometimes they don't. When I select a file and submit, my browser will show its doing "something" but nothing happens and it eventually "timesout." However, if I go back and try again it works the second time.

I've found another post that discusses this: http://ellislab.com/forums/viewthread/96387/

The solution in the above post seemed to be related to the local development environment. I am working locally, running Apache and PHP5 on OS X.

Here's my full controller method:
Code:
function create($project_id) { // Create a new page.
        $this->form_validation->set_rules('name', 'Page Name', 'required|max_length[50]');
        $this->form_validation->set_error_delimiters('<p class="error">', '</p>');

        if ($this->form_validation->run() == FALSE) {
            $this->ocular->set('page_title', 'Create a New Page');
            $this->ocular->render('task');
        } else {
            $config['upload_path'] = './_uploads/';
            $config['allowed_types'] = 'gif|jpg|png';

            $this->load->library('upload', $config);
            if ( ! $this->upload->do_upload()) {
                die('error:'.$this->upload->display_errors());
            }

            $this->load->library('markdown');
            $content_markdown = $this->input->post('content_markdown');
            $content_html = $this->markdown->translate($content_markdown);

            $page = array(
                'name' => $this->input->post('name'),
                'description' => $this->input->post('description'),
                'content_markdown' => $content_markdown,
                'content_html' => $content_html,
                'project_id' => $project_id,
                'order' => $this->input->post('order'));

            $saved_page_id = $this->Pages->save($page);

            $this->session->set_flashdata('message', 'Page was successfully created.');
            redirect("page/$saved_page_id");
        }
    }

Here's the pertinent information related to the file upload:

Code:
$config['upload_path'] = './_uploads/';
$config['allowed_types'] = 'gif|jpg|png';

$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) {
    die('error:'.$this->upload->display_errors());
}

As you can see above, I'm just starting out with this, and have simply told CI to upload the file to a folder, and if there's any errors to die and show those errors.

My view looks like this:
Code:
<fieldset class="page_image">
    &lt;input type="file" name="userfile" /&gt;
</fieldset>


Any help would be greatly appreciated.
#2

[eluser]bretticus[/eluser]
My initial advise would be to check your PHP upload settings...
...and make sure that you'r not uploading images that are too big (intermittently.)
#3

[eluser]Shaun Andrews[/eluser]
Thanks for the response. I'm not uploading large images; the file I was testing with is only 45k. But, to be clear, the file _will_ upload on the second try. It seems that every _odd_ upload works fine, while every _even_ upload timesout.
#4

[eluser]Out of Control[/eluser]
You mentioned OS X. Are you using Safari to test the uploads? I have seen this exact behaviour with Safari on both local and production development. If you are using Safari, try Firefox and see if you get the same response.
#5

[eluser]Shaun Andrews[/eluser]
How strange. Firefox seems to work just fine. Guess I'll ignore the issue for now in Safari. I'll report back if I find a cause/solution for this issue. If anyone know what's going on here in Safari, I'd love to hear from you.
#6

[eluser]crojac[/eluser]
See my post on this subj.

http://ellislab.com/forums/viewthread/146338/
#7

[eluser]Crimp[/eluser]
Can confirm this behavior in Safari. Sometimes it simply "hangs". Don't know why.




Theme © iAndrew 2016 - Forum software by © MyBB