I create a form which contain one image-array(name="image[]",type="file") to upload multiple images.And when user click on save button image is save in destination folder and with that thumbnail is create and it is save at its destination folder.
On local side everything is alright but when I upload it on server image is save in its destination but the thumbnails is not transfer to its destination folder.also folder for thumbnail is not create on server side.where on local-side folder is also create for thumbnails.
/* code for making thumbnails and upload it */
$fileName = $file[$fieldname]['name'][$i];
// $fileName = preg_replace("/[^A-Za-z0-9._]/", "",$fileName);
$fileTemp = $file[$fieldname]['tmp_name'][$i];
$dest = JPATH_ROOT . "\\"."images"."\\"."machines"."\\"."machines"."\\".$fileName;
$dest2 = JPATH_ROOT . "\\"."images"."\\"."machines"."\\"."thumbnails"."\\".$fileName;
$dest3 = JPATH_ROOT . "\\"."images"."\\"."machines"."\\"."thumbnails";
$dest3=str_replace("/","\\",$dest3);
$dest=str_replace("\\administrator/components/com_machine",null,$dest); //for image upload
$dest2=str_replace("\\administrator/components/com_machine",null,$dest2); // for thumbnail creation
$dest=str_replace("/","\\",$dest);
$dest2=str_replace("/","\\",$dest2);
$filePath =$dest;
$filePath2 =$dest2;
//Check for allowed extensions
$uploadedFileNameParts = explode('.',$fileName);
$uploadedFileExtension = array_pop($uploadedFileNameParts);
$uploadedFileExtension = strtolower($uploadedFileExtension);
$validFileExts = explode(',', 'jpeg,jpg,png,gif');
//assume the extension is false until we know its ok
$extOk = false;
//go through every ok extension, if the ok extension matches the file extension (case insensitive)
//then the file extension is ok
foreach($validFileExts as $key => $value){
if(preg_match("/$value/i", $uploadedFileExtension )){
$extOk = true;
$fileExtension = $value;
}
}
// Check if acceptable extension
if($extOk == false){
$info['error'] = 1;
$info['msg'] = JText::_('Not acceptable image extension');
return $info;
}
if($fileName){
// Try to upload file
if(JFile::upload($fileTemp, $filePath)){
// JFile::upload($newimage, $dest2);
//------------------thumbnail creation----------------
$n_width=100;
$n_height=100;
if(!is_dir($dest3))
{
mkdir($dest3);
chmod($dest3,0666);
}
//image creation
if($file[$fieldname]['type'][$i]=="image/gif")
{
$im=imagecreatefromgif("{$dest}");
$width=imagesx($im); // Original picture width is stored
$height=imagesy($im); // Original picture height is stored
$n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio
$newimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
if (function_exists("imagegif")) {
header("Content-type: image/gif");
imagegif($newimage,"{$dest2}");
chmod($dest2,0666);
//move_uploaded_file($newimage,$dest2);
}
elseif (function_exists("imagejpeg")) {
header("Content-type: image/jpeg");
imagejpeg($newimage,"{$dest2}");
chmod($dest2,0666);
}
}////////// end of gif file thumb nail creation//////////
////////////// starting of JPG thumb nail creation//////////
//echo $dest2;
if($file[$fieldname]['type'][$i]=="image/jpeg"){
$im=imagecreatefromjpeg("{$dest}");
$width=imagesx($im); // Original picture width is stored
$height=imagesy($im); // Original picture height is stored
$n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio
$newimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagejpeg($newimage,"{$dest2}");
chmod($dest2,0666);
// move_uploaded_file($newimage,$dest2);
}
if($file[$fieldname]['type'][$i]=="image/png"){
$im=imagecreatefrompng("{$dest}");
$width=imagesx($im); // Original picture width is stored
$height=imagesy($im); // Original picture height is stored
$n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio
$newimage=imagecreatetruecolor($n_width,$n_height);
imagecopyresized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
imagepng($newimage,"{$dest2}");
chmod($dest2,0666);
// move_uploaded_file($newimage,$dest2);
}
// move_uploaded_file($newimage,"$dest2");
// exit;
//------------------end thumbnail creation--------------
//JFile::upload($newimage, $dest3);
$info['error'] = 0;
$info['msg'] = JText::_('record saved');
return $info;
}
} else {
$info['error'] = 1;
$info['msg'] = JText::_('No image selected to upload');
return $info;
}