2

I want to upload a file using a registration form. I used File_Upload library of Codeigniter. But the file does not upload to the destination and no errors appears. This is just part of my code (All of them are really huge)

Controller (seeker_register.php):

public function submit(){
...
$this->load->model('mseeker_register');
$user_id = $this->mseeker_register->register($data);

View (vseeker_register.php):

$attr = array("class" => 'form-horizontal seeker_register','id' => 'form-seeker-register');
echo form_open_multipart('seeker_register/submit',$attr);
...
<div class="col-sm-6 col-sm-offset-3">
<input name="Aks" type="file" class="fileinput" accept=".jpg, .jpeg">
</div>

Model (mseeker_register.php):

...
// Prepare Aks
$config = array(
    'upload_path' => './img/users',
    'allowed_types' => 'jpg|jpeg|JPG|JPEG',
    'max_size' => '200',
    'max_width' => '1024',
    'max_height' => '768');

$this->upload->initialize($config);
$this->upload->do_upload('Aks');

$this->upload->display_errors();
exit();
...

This is $this->upload->data() output:

Array
(
    [file_name] => Clipboard-2.jpg
    [file_type] => image/jpeg
    [file_path] => D:/khayyamkar.ir/www/img/users/
    [full_path] => D:/khayyamkar.ir/www/img/users/Clipboard-2.jpg
    [raw_name] => Clipboard-2
    [orig_name] => 
    [client_name] => Clipboard-2.jpg
    [file_ext] => .jpg
    [file_size] => 156.42
    [is_image] => 1
    [image_width] => 
    [image_height] => 
    [image_type] => 
    [image_size_str] => 
)
3
  • check permission of your folder Commented May 13, 2015 at 5:06
  • I'm testing the code on XAMPP for Windows and the user is administrator. I have the permission to write. Commented May 13, 2015 at 5:22
  • 1
    You will get your problem if you can enable to print the error <code> error_reporting(-1); ini_set('display_errors', 'On'); </code> just past this at your page heading Commented May 13, 2015 at 6:10

2 Answers 2

3

When I scanned your code I realized that you you don't have a way to view the error(s).

To view what the error(s) are/is you need to use var_dump() or print_r() php method to view what are the error(s).

for example:

var_dump($this->upload->display_errors());

in your current code you need to change :

$this->upload->display_errors();
exit();

TO:

var_dump($this->upload->display_errors());
exit();

You need to identify the error first to come up with a solution.

:)

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

1 Comment

Thanks a lot... I didn't mention that. The error was: "The image you are attempting to upload exceedes the maximum height or width." I tried with a smaller image and it worked ...
2
public function register() {

    $config = array(
        'upload_path' => './img/user',
        'allowed_types' => 'jpg|jpeg|JPG|JPEG|png',
        'max_size' => '200',
        'max_width' => '1024',
        'max_height' => '768');

    $this->upload->initialize($config);

    // you need to make sure that the upload path is existing
    // and also check the folder permission to be rwxr-xr-x
    // if you installed in a server where permission is required
    // for you to create image inside the folder

    // create a folder img/user in the root directory of the project
    // where application or system located

    // this will check 
    if ($this->upload->do_upload('Aks')) {
        echo 'success'; die;
    } else {
        var_dump($this->upload->display_errors());die;
    }


}

see File Upload CodeIgniter

1 Comment

I am not able to understand what you have correct in your code that OP doesn't??

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.