how to upload doc, xls, ppt file ?

#1
[eluser]mahe11[/eluser]
hi all

i want to upload a document file like doc, ppt , xls, and pdf file.

plz help me...


Thanks in advance.

#2
[eluser]Cristian Gilè[/eluser]
After submit your form, before to call the upload library, echo
Code:
$_FILES[‘userfile’][‘type’]
and check if the mime is in config/mimes.php

Cristian Gilè

#3
[eluser]mahe11[/eluser]
Hi Cristian Gilè,
I use your suggestion
Code:
$_FILES[‘userfile’][‘type’]
but there is an error...
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined index: userfile

I also try...

Code:
echo $HTTP_POST_FILES["userfile"];

but gives same error...

my HTML code is
Code:
<input type="file" name="userfile" id="userfile" />

where is problem? plz help me.

#4
[eluser]InsiteFX[/eluser]
userfile is the name of the file that you want to upload!

Change userfile to the name of your file!

InsiteFX

#5
[eluser]mahe11[/eluser]
hi InsiteFX Sir,
one new problem i have face one more problem for uploading file, in Google chrome file cant upload but in Mozilla it upload :roll:
why it happen?
And also it upload only in localhost... not in my webhost.
plz help me...

#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

#7
[eluser]mahe11[/eluser]
I take help that from Codeigniter user guide. and use already.

#8
[eluser]Cristian Gilè[/eluser]
[quote author="InsiteFX" date="1295880633"]userfile is the name of the file that you want to upload!

Change userfile to the name of your file!

InsiteFX[/quote]

WRONG!!!

userfile is the file field name not the name of the file. To access the file name use
Code:
$_FILES['userfile']['name']


Cristian Gilè

#9
[eluser]InsiteFX[/eluser]
What can I say, It was long night LOL.

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.