Member Avatar for iamthwee

Hi guys,

This one has got me completely stumped. Here are my trouble shooting notes.

My upload script works absolutely fine without any changes on localhost. However, on the live production server my files do not get uploaded.

My view is:

<?php echo form_open_multipart('upload/do_upload');?>

        <input type="file" name="userfile" size="20" />

        <br/>
        <button type="submit" class="btn btn-success btn-s-xs " id="">Upload</button>
<?php echo form_close(); ?>

And my controller is...

      function do_upload()
      {
            /**
             * @Description: Make sure NOT to autoload this lib!!!
             *
             */


            $config['upload_path'] = "./uploads";

            $config['allowed_types'] = '*';



            $this->load->library('upload', $config);

            /**
             * @Description: unsuccessful
             * @params     : params
             * @returns    : return
             */
            if ( ! $this->upload->do_upload())
            {
                  echo $this->upload->display_errors('<p>', '</p>');
            }
            /**
             * @Description: successful
             * @params     : params
             * @returns    : return
             */
            else
            { 
                $data = array('upload_data' => $this->upload->data());




            }
      }

As you can see it is super simple. I've also set my 'uploads' folder to have 777 permissions. I don't have any htaccess files. In my config file I have $config['index_page'] = 'index.php';

So there can be no way any .htaccess files are causing a problem. Also there are NO htaccess files within the 'uploads' folder.

In my controller I've allowed for all filetypes to be uploaded and no restrictions on size. For testing on my live server I have tried to upload a tiny jpg, and a tiny text file. Again it doesn't work. But it DOES work on my localhost!!

The other strange thing is the file upload error message says 'You did not select a file to upload'

Which is stupid because I am, and it works fine in localhost.

The PHP versions are the same on localhost and on my production server. I have not changed the directory structure in localhost and my production server. All files are identical except for the baseurl which I've obviously changed to my domain address.

Localhost I'm using a linux server, my production server is centos, so effectively there should be no issues with file case sensitivity.

As I said before the uploads folder is writtable, and the only thing I have to work with is that confusing error message!

Any help would be most grateful. Thanks in advance!!!

Member Avatar for iamthwee

I forgot to mention I am autoloading these in my autoload file:

$autoload['helper'] = array('url','form','html','text','string','file');

Just incase anyone asks. Also I've got no jquery or javascript in the view files.

Hi!

I've experienced this kind of issue in past, it was due to a mismatch of mime-types and I fixed by updating the application/config/mimes.php file. But I was trying to upload PDFs and images.

Set the environment constant in the main index.php file to the development stage, set the log_threshold to 4 in the application/config/config.php file and then create a new method in your controller to get a verbose output:

public function verbose_upload()
{
    $config['upload_path'] = "./uploads";
    $config['allowed_types'] = '*';

    $this->load->library('upload', $config);
    $this->upload->do_upload();

    $data['errors'] = $this->upload->display_errors('<p>', '</p>');
    $data['result'] = print_r($this->upload->data(), true);
    $data['files']  = print_r($_FILES, true);
    $data['post']   = print_r($_POST, true);

    $this->load->view('result', $data);
}

And the view (result.php) will look like this:

<!DOCTYPE html>
<html>
<head>
    <title>Verbose Upload</title>
</head>
<body>

<?php 

    if($errors)
    {
        echo "<h3>Errors</h3>";
        echo $errors;
    }

    if($result)
    {
        echo "<h3>Result</h3>";
        print_r("<pre>".$result."</pre>");
    }

    if($files)
    {
        echo "<h3>FILES array</h3>";
        print_r("<pre>".$files."</pre>");
    }

    if($post)
    {
        echo "<h3>POST array</h3>";
        print_r("<pre>".$post."</pre>");
    }

?>

</body>
</html>

Now, no matter what happens you should see what is really sent from the browser. And check the CI logs to see if something is wrong.

If, for some reason, the Upload library is failing then you should get an output from the $_FILES array which is independent from CI, hopefully this output could help us to understand the issue.

Member Avatar for iamthwee

Sorry guys, after further investigation, I narrowed it down to a htaccess file in the directory above it.

The guy before me was an idiot and has created crazy complicated .htaccess files for all his sites.

I dare not tamper with it in case it removes some of the functionality of our legacy sites on this domain

My only option is to put this on another domain with no .htaccess on the root.

I tried the same files on a clean domain, same VPS, and the upload worked a treat.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.