CodeIgniter Forums
Upload function not running - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Upload function not running (/showthread.php?tid=24246)



Upload function not running - El Forum - 11-04-2009

[eluser]überfuzz[/eluser]
I'm building a simple form to mail script. It's supposed to attach a userfile to the mail.
Code:
function index()
    {
        if(isset($_POST['submit']))
        {
            //rules to <form> Setting $this->data['status']) if rules are broken

            $this->data['content'] = "form";
            $this->load->view('templates/standard', $this->data);

            if(!isset($this->data['status']))
            {

                echo "testing upload";   //This one echoes like it should.
                $test = do_upload();  //The print_r() test gives nada.

                print_r($test);


            }
        }
        else
        {

            $this->data['content'] = "form";
            $this->load->view('templates/standard', $this->data);
        }
    }






//function I'm wrestling form input : <?php echo form_upload('userfile', ''); ?>
    function do_upload()
    {
        $config['upload_path'] = './assets/temp/applications/';
        $config['allowed_types'] = 'txt|odt|doc|pdf';
        $config['max_size'] = '100';
        $config['xss_clean'] = TRUE;
        
        $this->load->library('upload', $config);
    
        if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());
            return $error;   //test
        }    
        else
        {
            $data = array('upload_data' => $this->upload->data());
            return TRUE;   //test
        }
    }

Edit, What am I doing wrong here?


Upload function not running - El Forum - 11-04-2009

[eluser]Flemming[/eluser]
Don't you need to use
Code:
$this->email->attach()
from the email class?

Edit: sorry - is the upload not working at all? Have you set the enctype of the form correctly?


Upload function not running - El Forum - 11-04-2009

[eluser]umefarooq[/eluser]
hi pass form file name to then it will upload you files and also you call your class parameters properly

Code:
$test = $this->do_upload();

<input type="file" name="upload" />
$this->upload->do_upload('upload');



Upload function not running - El Forum - 11-04-2009

[eluser]überfuzz[/eluser]
[quote author="flemming" date="1257351993"]Don't you need to use
Code:
$this->email->attach()
from the email class?

Edit: sorry - is the upload not working at all? Have you set the enctype of the form correctly?[/quote]
I think so. form_open_multipart('test') gives:
Code:
<form action="http://www.-----.com/test" method="post" enctype="multipart/form-data">



Upload function not running - El Forum - 11-04-2009

[eluser]überfuzz[/eluser]
[quote author="umefarooq" date="1257352180"]hi pass form file name to then it will upload you files and also you call your class parameters properly

Code:
$test = $this->do_upload();

<input type="file" name="upload" />
$this->upload->do_upload('upload');
[/quote]
Its stated in the user_guide that upload will assume that there is a field called userfile. So the call should work without passing the field name


Upload function not running - El Forum - 11-04-2009

[eluser]umefarooq[/eluser]
yes it will work fine if you field name is "userfile" that is default filename parameter in upload library if you defining you own field name just like upload or uploadfile then you have to give field name as parameter in do_upload() function you can check user_guide it is also there