Welcome Guest, Not a member yet? Register   Sign In
Problems while uploading and Editing multiple images.
#1

[eluser]yorvik[/eluser]
Hello

I am using codeigniter for a small custom CMS. Now I need to make a form for uploading and editing multiple images. The main principle is. I upload a picture put a watermark on top of the original image. From the original image a make thumbnail and a resized image.

When I only upload 1 image everythings works fine , watermark is added , thumbnail and resized images are created. The problem starts when uploading more larger images.

This is my code: (inside a controller)
Code:
function do_upload($kunstwerkId) {
        $gallery_path_resized = $_SERVER['DOCUMENT_ROOT'].'\img\schilderijResized/';
        $gallery_path = $_SERVER['DOCUMENT_ROOT']. '\img\schilderij/';
        $gallery_path_cache = $_SERVER['DOCUMENT_ROOT'].'\img\cache/';
        $gallery_path_font = $_SERVER['DOCUMENT_ROOT'].'\font/';
        $gallery_watermark_path =  $_SERVER['DOCUMENT_ROOT']. '\img\watermark/watermark.png';

        $this->load->model('art_model');

        // FotoAlbum standard on 0
        $fotoAlbum = 0;
        $allowed = array( 'jpg','jpeg','png','gif','wbmp' );
        $maxsize = 500000;


        $files = array();
        foreach ($_FILES['test'] as $name => $parts) {
            foreach ($parts as $key => $part) {
                $files[$key][$name] = $part;
            }
        }
        $i = 0;
        
        foreach ($files as $file) {
            if (is_uploaded_file($file['tmp_name'])) {
                if ($file['name'] !== '' && $file['error'] == 0) {
                    $extn = strrev(substr(strrev($file['name']), 0, ( strpos(strrev($file['name']), '.'))));
                    if (in_array($extn, $allowed)) {
                        if (filesize($file['tmp_name']) <= $maxsize) {
                            $path = md5(uniqid(rand(), true)) . ".{$extn}";

                            if (copy($file['tmp_name'],$gallery_path . $path)) {

                                 // ADD WATERMARK OVERLAY TO THE ORIGINAL IMAGE
                                $config['source_image'] = $gallery_path . $path;
                                $config['wm_type'] = 'overlay';
                                $config['wm_vrt_alignment'] = 'middle';
                                $config['wm_hor_alignment'] = 'center';
                                $config['wm_padding'] = '10';
                                $config['wm_overlay_path'] = $gallery_watermark_path;
                                $config['wm_opacity'] = '60';

                                $this->image_lib->initialize($config);
                                $this->image_lib->watermark();
                                $this->image_lib->clear();
                                
                                $config = array();
                                $config['image_library'] = 'gd2';
                                $config['source_image'] = $gallery_path . $path;
                                $config['maintain_ratio'] = TRUE;
                                $config['height']   = 560;
                                $config['width']     = 340;
                                $config['new_image'] = $gallery_path_resized . $path;

                                $this->image_lib->initialize($config);
                                $this->image_lib->resize();
                                $this->image_lib->clear();
                                
                                                                
                                $data = array(
                                    'fotoNaam' => $path,
                                    'schilderijId' => $kunstwerkId,
                                    'fotoAlbum' => $fotoAlbum
                                    );
                                $lastAddedPictureId = $this->art_model->add_Picture($data);

                                if ($i == 0) { // First picture must always be the Album picture. Only create thumbnail when i == 0
                                    $fotoNaam = substr($path, 0, strrpos($path, '.'));
                                    $data = array(
                                        'fotoAlbum' => 1
                                    );

                                    $this->art_model->update_Picture($data,$kunstwerkId,$lastAddedPictureId);

                                    $config = array();
                                    $config['image_library'] = 'gd2';
                                    $config['source_image'] = $gallery_path . $path;
                                    $config['maintain_ratio'] = TRUE;
                                    $config['height']   = 100;
                                    $config['width']     = 100;
                                    $config['new_image'] = $gallery_path_cache . $fotoNaam . "Small.png";

                                    $this->image_lib->initialize($config);
                                    $this->image_lib->resize();
                                    $this->image_lib->clear();
                                }
                            }
                        }
                    }
                }
                // Make sure counter is always upgraded by 1
                $i++;
            }
        }
    }

Does anybody know a better solution for doing this? Or am I doing something the wrong way?

Thanks in advance

Joachim Vanthuyne
#2

[eluser]yorvik[/eluser]
NO solutions ??




Theme © iAndrew 2016 - Forum software by © MyBB