13
If you have multiple images loop through $_POST['xoops_upload_file'] array:
//upload media
include_once XOOPS_ROOT_PATH.'/class/uploader.php';
$allowed_mimetypes = array('image/gif', 'image/jpeg', 'audio/mpeg');
$maxfilesize = 50000000;
$maxfilewidth = 4000;
$maxfileheight = 3000;
$uploadDir = '/uploads';
print_r($_POST['xoops_upload_file']);
print " count : ".count($_POST['xoops_upload_file']);
$uploader = new XoopsMediaUploader(XOOPS_ROOT_PATH.$uploadDir, $allowed_mimetypes, $maxfilesize, $maxfilewidth, $maxfileheight);
if(isset($_POST['xoops_upload_file'][0]))
{
for($i=0;$i {
if($uploader->fetchMedia($_POST['xoops_upload_file'][$i]))
{
if (!$uploader->upload())
{
$errors[] = $uploader->getErrors();
}
else
{
$filename=$uploader->getSavedFileName() . '
';
$saved_path=$uploader->getSavedDestination();
$mediaType='';
$mediaType=$uploader->getMediaType();
$j=strpos($mediaType,'/');
$mediaType=substr($mediaType,++$j);
$file_path = XOOPS_ROOT_PATH.'/modules/myModule/media/';
$new_thumb_file=XOOPS_ROOT_PATH.$uploadDir.'/tmpT';
touch($new_thumb_file);
createThumbImage($saved_path,$new_thumb_file,$mediaType);
$name='uniqueName';
$s1=rename($new_thumb_file,$file_path.'thumbs/'.$name);
$new_large_file=XOOPS_ROOT_PATH.$uploadDir.'/tmpL';
touch($new_large_file);
createLargeImage($saved_path,$new_large_file,$mediaType);
$name='uniqueName';
$s2=rename($new_large_file,$file_path.'large/'.$name);
//delete orginal uploaded file
unlink($saved_pathh);
if(!$s1||!$s2)
{
//manage filesystem errors
}
}
}
else
{
//manage uploader errors
//$errors[] = $uploader->getErrors();
}
}
}
function createThumbImage($filename,&$new_file,$format)
{
// Set a maximum height and width
$width = 100;
$height = 100;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if($width && ($width_orig < $height_orig))
{
$width=($height / $height_orig) * $width_orig;
}
else
{
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
if($format=='jpeg')imagejpeg($image_p,$new_file);
if($format=='gif')imagegif($image_p,$new_file);
}