Welcome Guest, Not a member yet? Register   Sign In
Standard File Uploading Error
#1

[eluser]kane.zach[/eluser]
Hey all,

I'm going insane at the moment trying to figure this incredibly low level problem. I've been messing with image uploading elsewhere and things are going smoothly.

Now, just to start out on a new project, I've got up the basic CI File Upload views and controller, precisely from the User Guide (except for the max_size var so I don't have to look for tiny files during testing). I have an uploads dir in my public html set to 777. I've checked my php.ini and file_uploads is ON, max_file_uploads is 20 and upload_max_filesize is 2M. None of the files I'm testing with are close to that size. upload_tmp_dir has no value (if this means something with respect to this?)

Once I submit I just get back the upload_form with the error 'you did not select a file to upload', obviously following the controller's control statement.

Does anybody have anything else I can check or alter? It's late so maybe I left something out but at the moment I'm stumped and it's infuriating!
#2

[eluser]kkristo[/eluser]
Hope you are don't submit form via ajax/jquery. Jquery can't upload image. Then check from form what correct Image name are:
<input type=file name="TestImage">

and controller
$this->upload->do_upload('TestImage')
#3

[eluser]kane.zach[/eluser]
Oh no, of course I'm not messing with jQuery or anything like that now. I seriously have only the 2 Views and 1 Controller from the User Guide. I changed the input's name to something else beside 'userfile' making sure to add that to do_upload()'s params and still nothing.

...I just double checked my php config. register_globals is set to off. my other host has that set to on by default. I know CI 'disables' the GET var but I'm assuming that the Upload lib probably accesses $_FILES no? How else would that be accessed?
#4

[eluser]kkristo[/eluser]
OK.. before do_upload('MuFile') try
print_r($_FILES);
If you don't see variables, then server have disabled file upload.
#5

[eluser]kane.zach[/eluser]
Well, i put that at the top of my form and i get "Array ( )"
#6

[eluser]kkristo[/eluser]
After form submit $_FILES can't be empty. I think you have some typo html.
#7

[eluser]LuckyFella73[/eluser]
Did you set up a multipart-form?

Would be helpfull if you show the form-script
and the controller script handling the form data.
Makes it much easier to help.
#8

[eluser]kane.zach[/eluser]
Okay, this is all that is going on:

Controller
Code:
<?php

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'] = 'gif|jpg|png';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        
        $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);
        }
    }    
}

Initial View
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;

Success View
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;
#9

[eluser]LuckyFella73[/eluser]
Hej kane.zach,

I did set up a fresh CI installation and copied and pasted
your code. No error - everything works like expected.

So the error must be anywhere else...
#10

[eluser]kane.zach[/eluser]
Well, it's solved?

I'm working on this on a host a friend setup which had a lot of strange dirs and files for proprietary stuff. I saved all those locally, burned the entire public_html directory to the ground (hah), and re-downloaded the latest CI.

Setup, added my controller & views back and things are cool...? I suppose I shouldn't complain. Machine mysticism.




Theme © iAndrew 2016 - Forum software by © MyBB