01-19-2016, 04:48 AM
(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.
Resize Function
Controller
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
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);
}
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_name, 100, 100)
);
}
$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);
}
}
There's only one rule - please don't tell anyone to go and read the manual. Sometimes the manual just SUCKS!