[eluser]chefnelone[/eluser]
Hello
I have this code to upload a image and resize it if the width or height of the uploaded image is bigger than 500px.
I works fine with a image of: 800px X 600px (width x height)
...but it doesn't work with a image of: 1200px X 900px
This is the real code:
controllers/index.php
Code:
class Index extends MY_Controller{
function upload_image(){
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '5000';
$config['max_height'] = '5000';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_image', $error);
}else{
$upload_data = $this->upload->data();
if($upload_data['image_width'] > 500 || $upload_data['image_height'] > 500 ){
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$upload_data['file_name'];
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 500;
$config['height'] = 500;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->resize()){
$error = $this->image_lib->display_errors();
print_r($error);
}
}
$data['upload_data'] = $upload_data;
$this->load->view('upload_image', $data);
}
}
}
views/upload_image.php
Code:
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h1>Upload Photo</h1>
<?php if(isset($error)){echo $error;}?>
<?php if(isset($upload_data)){ ?>
<ul>
<?php foreach($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<?php } ?>
<?php echo form_open_multipart('index/upload_image');?>
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
Where is my mistake??