0

My problem is that I have a code that works on localhost but not on production server. I want to upload a file through a form. In localhost everything works fine, but on production server, I get the 'you did not select a file to upload' error.

The view part

<?php echo form_open_multipart('Ajax/do_upload');?>
<input type="file" name="file">
<input type="submit" name="submit" value="upload image" />
<?php echo form_close();?>

The controller part (controller Ajax, function do_upload)

public function do_upload(){

    $config['upload_path']          = './assets/images/usr_uploads/';
    $config['allowed_types']        = 'gif|jpg|png|jpeg';
    $config['max_size']             = 5000;
    $config['max_width']            = 2048;
    $config['max_height']           = 2048;
    $config['overwrite']           = true;

    $this->load->library('upload', $config);
    $this->upload->initialize($config);
    $filename = $_FILES['file']['name'];

    if (!$this->upload->do_upload("file")){
        //$data['error'] = "An error occurred while uploading the image.";
        $error = array('error' => $this->upload->display_errors());
        //echo $filename;
        print_r($_FILES);
        $this->load->view('template/head.php');
        $this->load->view('profileview.php', $error);
        $this->load->view('template/footer.php');
    } else {
        $filename = $_FILES['file']['name'];
        $data['up_ok'] = $filename;
        print_r($_FILES);
        $this->savefn($filename);
        $this->updatesesssion();
        $this->load->view('template/head.php');
        $this->load->view('profileview.php', $data);
        $this->load->view('template/footer.php');
    }
}

.htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L] 

So the problem is that when on production server, it does not get any file from the form. On localhost it works as it should. I cannot find the cause of this problem and I have tried almost everything I have found. I have also tried with the default userfile, which again works on localhost but not on server and I have already set the folder permissions to 777.

19
  • Is $config['base_url'] value set well? .htaccess too? Commented Aug 6, 2017 at 10:28
  • base_url is fine. htaccess file: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] Commented Aug 6, 2017 at 10:30
  • Please copy that and edit your question with code tags to be readable. Commented Aug 6, 2017 at 10:31
  • You only need to load config one remove this $this->upload->initialize($config); Commented Aug 6, 2017 at 10:33
  • @wolfgang1983 I did and it does not work Commented Aug 6, 2017 at 10:37

2 Answers 2

0

I don't known this function, try change $this->savefn($filename); to $image = $this->upload->data(); print_r($image['file_name']);

Sign up to request clarification or add additional context in comments.

Comments

0

I think your domain is not fetching at live server. use ip address or below global variable $_SERVER try to change $config['base_url'] = $_SERVER['SERVER_NAME'];

1 Comment

This answer was flagged as low-quality because of its length and content. Suggest adding a description of what it does and how it answers the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.