Welcome Guest, Not a member yet? Register   Sign In
how to upload doc, xls, ppt file ?
#6

[eluser]InsiteFX[/eluser]
Try this!

controller upload.php:
Code:
class Upload extends Controller {
    
    function Upload()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));
    }
    
    function index()
    {    
        $this->load->view('upload_form', array('error' => ' ' ));
    }

    function do_upload()
    {
        $config['upload_path'] = './uploads/';
        $config['allowed_types'] = 'doc|ppt|xls|pdf';
        $config['max_size']    = '0';
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            
            $this->load->view('upload_form', $error);
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            
            $this->load->view('upload_success', $data);
        }
    }    
}
?>

view upload_form:
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:
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;

make sure that the uploads directory is writeable!

echo out what you are getting!

InsiteFX


Messages In This Thread
how to upload doc, xls, ppt file ? - by El Forum - 01-14-2011, 05:04 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-14-2011, 07:31 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 02:45 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 02:50 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 03:47 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 07:29 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 08:24 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 09:05 AM
how to upload doc, xls, ppt file ? - by El Forum - 01-24-2011, 04:32 PM



Theme © iAndrew 2016 - Forum software by © MyBB