Welcome Guest, Not a member yet? Register   Sign In
How to avoid $_POST resending data?
#5

[eluser]webbymonk[/eluser]
Similiar to what i did...

but my case is for temporary data,,,
After the user confirm, the data will be sent to database,,,so I will have to use session...

I think redirecting is good especially for upload file case.

But I don't know how to write the upload data into session because i have multiple upload field

$this->upload->data() is multi dimension array...

Here is my code i wrote in the helper

Code:
<?php



function generate_code($length = 10){

    
    if ($length <= 0)
    {
           return false;
    }
            
    $code = "";
    $chars = "abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ123456789";
    srand((double)microtime() * 1000000);
    for ($i = 0; $i < $length; $i++)
    {
        $code = $code . substr($chars, rand() % strlen($chars), 1);
    }
    return $code;

}


function generatePhotoThumbnail($source, $newimage)
{
    $CI = & get_instance();
    
            $config['image_library'] = 'GD2';
            $config['source_image'] = $source;
            $config['create_thumb'] = TRUE;
            $config['thumb_marker'] = '_thumb';
            $config['master_dim'] = 'width';
            $config['quality'] = 75;
            $config['maintain_ratio'] = TRUE;
            $config['width'] = 175;
            $config['height'] = 175;
            $config['new_image'] = './assets/public/placesPhotos/thumb/'.$newimage;

            //$this->image_lib->clear();
            $CI->image_lib->initialize($config);
            //$this->load->library('image_lib', $config);
            $CI->image_lib->resize();
            
            
            
            rename($source,'./assets/public/placesPhotos/'.$newimage);
            
}


function processPhoto($uploaddata, $reviewID)
{
        $CI = & get_instance();
           $gmt=false;
        $time = ($gmt)  ? gmstrftime("%Y-%m-%d %H:%M:%S", time()) : strftime("%Y-%m-%d %H:%M:%S", time());
        //Move Files To User Folder
        foreach($uploaddata as $key => $value)
        {
            //Gen Random code for new file name
            $randomcode = generate_code(12);
            
            $newimagename = $randomcode.$value['file_ext'];
            
        
            generatePhotoThumbnail($value['full_path'],$newimagename);
            
            //Make Some Variables for Database
            $imagename = $newimagename;
            $thumbnail = $randomcode.'_thumb'.$value['file_ext'];
      
          
            
           $CI->load->model('photo_model');
            
            $photoInfo = array(
                'place_id' => $reviewID,
                'imagename' => $imagename,
                'thumbnail' => $thumbnail,
                'title' => $value['raw_name'],
                'width' => $value['image_width'],
                'height' => $value['image_height'],
                'filesize' => $value['file_size'],
                'description' => '',
                'timestamp' => $time,
                'up_status' => 1
            );
            
            $CI->photo_model->insertPhoto($photoInfo);
      /*      //Add Pic Info To Database
            $this->db->set('tour_id', $picInfo['tour_id']);
            $this->db->set('imagename', $imagename);
            $this->db->set('thumbnail', $thumbnail);
            $this->db->set('filesize', $filesize);
            $this->db->set('width', $width);
            $this->db->set('height', $height);
            $this->db->set('up_status', '1');
            $this->db->set('timestamp', $picInfo['timestamp']);
            
            //Insert Info Into Database
            return $this->db->insert('pictures');
*/
        }
        
}




?&gt;

and this is my controller
Code:
$this->load->helper(array('file','photo_upload_helper'));

    $config['upload_path'] = './img/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']    = '2048'; //2 meg
    $config['max_width']  = '1024';
    $config['max_height']  = '1024';
                        
         $this->load->library('upload',$config);
    $this->load->library('image_lib');    
        foreach($_FILES as $key => $value)
    {
         if( ! empty($value['name']))
          {
                  if(!$this->upload->do_upload($key))
               {                                
            $data['error_upload'][] = $this->upload->display_errors();
            $sessUploadError = $this->upload->display_errors();
            $this->session->set_flashdata($sessUploadError);          
            //$errors = TRUE;
         }
           else
          {
            // Build a file array from all uploaded files
            
             $sessUploadData = $this->upload->data();                                  
                      $this->session->set_flashdata($sessUploadData);
             processPhoto(array($this->upload->data()), $placeID);
         }
    }
}


Messages In This Thread
How to avoid $_POST resending data? - by El Forum - 10-09-2008, 09:43 PM
How to avoid $_POST resending data? - by El Forum - 10-10-2008, 07:10 AM
How to avoid $_POST resending data? - by El Forum - 10-13-2008, 10:53 PM
How to avoid $_POST resending data? - by El Forum - 10-13-2008, 11:20 PM
How to avoid $_POST resending data? - by El Forum - 10-13-2008, 11:43 PM



Theme © iAndrew 2016 - Forum software by © MyBB