CodeIgniter Forums
Problem with image resize & absolute path - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Problem with image resize & absolute path (/showthread.php?tid=33649)



Problem with image resize & absolute path - El Forum - 09-03-2010

[eluser]vollossy[/eluser]
Hello. I've got problem with image resizing. When i try to set $config['new_image'] to absolute path i get an error: "Unable to save the image. Please make sure the image and file directory are writable.", but whe i set it to relative path - al works correct.
Here's the code:
Code:
$this->CI->lang->load('error', 'russian');      
        list($currWidth, $currHeight) = getimagesize($source);
        $sidesRelation = $currWidth / $currHeight;
        if ($onlyShrink && ($sidesRelation > 1)) {
            $config['image_library'] = 'gd2';
            $config['source_image'] = $source;
            $config['new_image'] = 'Y:\home\rb26\www\uploads\new_image.jpg';
            $config['width'] = $newWidth;
            $config['height'] = $newWidth * $sidesRelation;
            var_dump($config);
            $this->CI->load->library('image_lib', $config);
            if ($this->CI->image_lib->resize()) {
                return "ok";
            } else {
                return $this->CI->image_lib->display_errors();
                //return $this->CI->lang->line('ssitl_error');
            }
        }else{
            return $this->CI->lang->line('ssitl_error_only_shrink');
        }



Problem with image resize & absolute path - El Forum - 09-03-2010

[eluser]skunkbad[/eluser]
When new_image is set with an absolute path, it gets run through php's realpath function. Then str_replace changes that path by switching backslashes with forward slashes. I'm not sure, but this might be your problem, because you are on Windows. As an experiment, you might try hard coding the absolute path into the Image_lib to see if realpath or that str_replace is the reason why your absolute path is failing.


Problem with image resize & absolute path - El Forum - 09-03-2010

[eluser]vollossy[/eluser]
Problem solved, thanks. I think that problem was in switching backslashes with forward slashes, as you said. But i solved this by adding BASEPATH to my variable