[eluser]murphy2006[/eluser]
Hi again,
Another small problem has arisen. I am using SWFupload for the images and when I upload an image it works perfectly fine but the database get 12 extra posts + plus the correct post. Why is that, I think it has to be something with the looping process.
Code:
if ( ! $this->upload->do_upload('Filedata'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('albums_upload', $error);
} else {
$data = array('upload_data' => $this->upload->data());
$res = $this->upload->data();
$i=0;
foreach ($res as $rese) {
$test =$i+1;
///////////////////////////////////////////////////////////
//
// Create the mini image
//
///////////////////////////////////////////////////////////
$imgfile = $res['full_path'];
///////////////////////////////////////////////////////////
//
// Load the Image Library
//
///////////////////////////////////////////////////////////
$this->load->library('image_lib');
///////////////////////////////////////////////////////////
//
// Set the configuration for the mini image
//
///////////////////////////////////////////////////////////
$config['image_library'] = 'GD2';
$config['source_image'] = $imgfile;
$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = FALSE;
$config['quality'] = '95%';
$config['width'] = 51;
$config['height'] = 50;
$config['master_dim'] = 'width';
$this->image_lib->initialize($config);
$this->image_lib->resize();
///////////////////////////////////////////////////////////
//
// Set image size
//
///////////////////////////////////////////////////////////
$width = $res['image_width'];
$height = $res['image_height'];
///////////////////////////////////////////////////////////
//
// Set the configuration for the master image
//
///////////////////////////////////////////////////////////
$config2['image_library'] = 'GD2';
$config2['source_image'] = $imgfile;
$config2['create_thumb'] = FALSE;
$config2['maintain_ratio'] = TRUE;
$config2['quality'] = '95%';
if ($width > 500) {
$config2['width'] = 500;
} else {
$config2['width'] = $width;
}
if ($height > 300) {
$config2['height'] = 300;
} else {
$config2['height'] = $height;
}
$this->image_lib->initialize($config2);
$this->image_lib->resize();
///////////////////////////////////////////////////////////
//
// Gather the incoming data into variables
//
///////////////////////////////////////////////////////////
$owner = $_POST["owner"];
$album = $_POST["album"];
///////////////////////////////////////////////////////////
//
// Copy the uploaded files with new name
//
///////////////////////////////////////////////////////////
$random = rand(0,999999999);
$thumb = "_thumb";
copy($res['file_path'].$res['raw_name'].$res['file_ext'],$res['file_path'].$owner.'_'.$random.$res['file_ext']);
copy($res['file_path'].$res['raw_name'].'_thumb'.$res['file_ext'],$res['file_path'].$owner.'_'.$random.$thumb.$res['file_ext']);
///////////////////////////////////////////////////////////
//
// Delete the old images
//
///////////////////////////////////////////////////////////
$delete = $res['file_path'].$res['raw_name'].$res['file_ext'];
$delete2 = $res['file_path'].$res['raw_name'].'_thumb'.$res['file_ext'];
unlink($delete);
unlink($delete2);
///////////////////////////////////////////////////////////
//
// Put the incoming date in variables
//
///////////////////////////////////////////////////////////
$new_name = $owner.'_'.$random;
$date = now();
$dbentry = array(
'aco_owner' => $owner,
'aco_title' => $new_name,
'aco_album' => $album,
'aco_ext' => $res['file_ext'],
'aco_created' => $date
);
///////////////////////////////////////////////////////////
//
// Save the image to the database
//
///////////////////////////////////////////////////////////
$this->db->insert('fe_albums_content', $dbentry);
}
///////////////////////////////////////////////////////////
//
// Display the target page
//
///////////////////////////////////////////////////////////
$this->load->view('albums_upload', $data);
}
}
Thankful for a quick reply,
/Daniel