[eluser]Robert May[/eluser]
I've been wailing my head against my upload/thumbnail generation script since yesterday. It's run at the end of a multiple file upload, so it runs a foreach loop for each item in the string passed by Ajax. I've finally got it to the point where it doesn't generate errors, but the thumbnail file being created is now just a 200x200 black square.
If anyone has any ideas I'd be most grateful!
The string arrives as file=blah.jpg&file=arr.jpg& etc. The array_pop removes the last item which only includes a &.
The paths are all correct and have been tested.
Here's the function:
Code:
function upload(){
$newFileName = $this->input->post("newFileName");
$fileArray = explode('&', $newFileName);
$badelete = array_pop($fileArray);
$result = '';
foreach($fileArray as $file){
$aFile = explode('=', $file);
$aFile = $aFile[1];
$this->image_lib->clear();
$sourceimage = $_SERVER['DOCUMENT_ROOT'].'/gallery/'.$aFile;
$minusExtension = explode('.', $aFile, 2);
$filename = $minusExtension[0];
$extension = $minusExtension[1];
$thumbnail = $filename.'_thumb.'.$extension;
$newimage = $_SERVER['DOCUMENT_ROOT'].'/gallery/'.$thumbnail;
// Make squarethumb
$config['image_library'] = 'GD2';
$config['source_image'] = $sourceimage;
$config['new_image'] = $newimage;
$config['maintain_ratio'] = TRUE;
$config['width'] = '200px';
$config['height'] = '200px';
$this->image_lib->initialize($config);
if (!$this->image_lib->resize()){
echo "<br />Fullsize<br />";
echo $this->image_lib->display_errors();
}
else {
$this->image_lib->clear();
if(!is_file($newimage)){
echo "Thumbnail file not found";
}
else {
$config2['image_library'] = 'GD2';
$config2['x_axis'] = 200;
$config2['y_axis'] = 200;
$config2['create_thumb'] = FALSE;
$config2['maintain_ratio'] = FALSE;
$config2['source_image'] = $newimage;
$this->image_lib->initialize($config2);
if (!$this->image_lib->crop()){
echo "<br />Thumbnail<br />";
echo $this->image_lib->display_errors();
}
$this->image_lib->clear();
}
}
$data = $this->gallery_model->add_image($aFile);
}
}