Welcome Guest, Not a member yet? Register   Sign In
[HELP] Upload file with do_upload doesn't work please help
#1

[eluser]Unknown[/eluser]
Hi, i'm newbie in CI. :red:
I copied this code from codeigniter tutorial

Controller
Code:
<?php

class Upload extends 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'] = './file_download/';
        $config['allowed_types'] = 'gif|jpg|png|doc|docs|xls|xlsx|pdf';
        $config['max_size']    = '10000';
        $this->load->library('upload', $config);
                $this->upload->initialize($config);
  
        if ( ! $this->upload->do_upload('userfile'))
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('upload_form', $error);
                        echo "error";
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());
            $this->load->view('upload_success', $data);
        }
    }
}
?>

View: upload_form.php
Code:
<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 />

&lt;input type="submit" value="upload" /&gt;

&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;

View: upload_success.php
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Upload Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

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

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

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

&lt;/body&gt;
&lt;/html&gt;

the result after i click upload button, it only shows blank white page. i check the directory but still empty. I put folder "file_download" one level with "system" folder.

any help please...




Theme © iAndrew 2016 - Forum software by © MyBB