Welcome Guest, Not a member yet? Register   Sign In
[Solved] Problem with image resize codeigniter
#1

(This post was last modified: 01-20-2016, 12:53 AM by wolfgang1983.)

On my project I am creating a bootstrap modal where I can view all images in side a selected folder.

The problem I am having is I have the correct folder permissions on my uploads / cache folder but still trows error below.

Any suggestions why this is happening and how to solve this.

Code:
A PHP Error was encountered

Severity: Warning

Message: getimagesize(C:/wamp/www/riwakawebsitedesigns/uploads/cache): failed to open stream: Permission denied

Filename: libraries/Image_lib.php

Line Number: 1643

Backtrace:

File: C:\wamp\www\riwakawebsitedesigns\application\modules\admin\controllers\common\Upload.php
Line: 58
Function: initialize

File: C:\wamp\www\riwakawebsitedesigns\application\modules\admin\controllers\common\Upload.php
Line: 35
Function: resize_image

File: C:\wamp\www\riwakawebsitedesigns\index.php
Line: 295
Function: require_once
Resize Function

PHP Code:
public function resize_image($file_name$width$height) {
        $this->load->library('image_lib');

        if (!file_exists(FCPATH 'uploads/cache/' $file_name)) {

            $config['image_library'] = 'gd2';
            $config['source_image'] = './uploads/' $file_name;
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = FALSE;
            $config['width'] = $width;
            $config['height'] = $height;
                
            $config
['new_image'] = './uploads/cache/' $file_name;

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

               $this->image_lib->resize();

        }

        return base_url('uploads/cache/' $file_name);
        
    

Controller

PHP Code:
<?php

class Upload extends MX_Controller {

    public function 
index() {

        if (
$this->input->get('directory')) {
            
$directory FCPATH 'uploads/' $this->input->get('directory');
        } else {
            
$directory FCPATH 'uploads/';
        }

        
$directories glob($directory '*'GLOB_ONLYDIR);

        
$data['images'] = array();

        if (!
$directories) {
            
$directories = array();
        }

        
// Get files
        
$files glob($directory '*.{jpg,jpeg,png,gif,JPG,JPEG,PNG,GIF}'GLOB_BRACE);

        if (!
$files) {
            
$files = array();
        }

        
// Merge directories and files
        
$images array_merge($directories$files);

        foreach (
$images as $image) {
            
$file_name basename($image);
            
$data['images'][] = array(
                
'name' => $file_name,
                
'href' => $this->resize_image($file_name100100)
            );

        }

        
$this->load->view('template/common/upload'$data);
    }

public function 
resize_image($file_name$width$height) {
        $this->load->library('image_lib');

        if (!file_exists(FCPATH 'uploads/cache/' $file_name)) {

            $config['image_library'] = 'gd2';
            $config['source_image'] = './uploads/' $file_name;
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = FALSE;
            $config['width'] = $width;
            $config['height'] = $height;
                
            $config
['new_image'] = './uploads/cache/' $file_name;

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

               $this->image_lib->resize();

        }

        return base_url('uploads/cache/' $file_name);
        
    
}



Attached Files
.php   Upload.php (Size: 1.49 KB / Downloads: 105)
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply


Messages In This Thread
[Solved] Problem with image resize codeigniter - by wolfgang1983 - 01-19-2016, 04:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB