Приветствую!
Не так давно изучаю modx в связи с этим возник вопрос:
Как разрешить загружать более одной аватарки из настроек профиля пользователя!?
Регистрация и аутентификация организована на базе доп. Login, одну аватарку можно загрузить при помощи снипета Avatar (автора не знаю, нашел на одном из форумов посвящённым cms), его содержимое:
<?php
if (empty($modx)) return '';
// initialize output;
$output = true;
$counter = 1;
// valid extensions
$ext_array = array('jpg', 'JPG', 'JPEG', 'png');
// create unique path for this form submission
$uploadpath = 'assets/avatars/';
// get full path to unique folder
$target_path = $modx->config['base_path'] . $uploadpath;
$sf = 'avatar';
$file = $_FILES[$sf];
// Get Filename and make sure its good.
$filename = basename( $file['name'] );
// Get file's extension
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$ext = mb_strtolower($ext); // case insensitive
// is the file name empty (no file uploaded)
if($filename != '' && isset($_POST['updpword-btnnn'])) {
// is this the right type of file?
if(in_array($ext, $ext_array)) {
// clean up file name and make unique
$filename = 'user'.$modx->user->get('id') . '.' . $ext;
// full path to new file
$myTarget = $target_path . $filename;
$myTargetTemp = $target_path . '_' . $filename;
if(move_uploaded_file($file['tmp_name'], $myTargetTemp)) {
require_once MODX_CORE_PATH.'model/phpthumb/phpthumb.class.php';
$phpThumb = new phpThumb();
$phpThumb->setSourceFilename($myTargetTemp);
$phpThumb->setParameter('w', 150);
$phpThumb->setParameter('h', 150);
$phpThumb->setParameter('zc', '1');
$phpThumb->setParameter('q', '150');
if ($phpThumb->GenerateThumbnail()) {
if ($phpThumb->RenderToFile($myTarget)) {
$avas=glob($target_path . '/user'.$modx->user->get('id') . ".*");
if(is_array($avas)) foreach ($avas as $fpath) {
if(basename($fpath) != basename($myTarget)) @unlink($fpath);
}
// set a new placeholder with the new full path (if you need it in subsequent hooks)
$myFile = $uploadpath . $filename;
$hook->setValue($sf,$myFile);
// set the permissions on the file
if (!chmod($myTarget, 0644)) { /*some debug function*/ }
} else {
// File not uploaded
$errorMsg = 'There was a problem uploading the file.';
$hook->addError($sf, $errorMsg);
$output = false; // generate submission error
}
}
} else {
// File not uploaded
$errorMsg = 'There was a problem uploading the file.';
$hook->addError($sf, $errorMsg);
$output = false; // generate submission error
}
@unlink($myTargetTemp);
/*
// is the file moved to the proper folder successfully?
if(move_uploaded_file($file['tmp_name'], $myTarget)) {
// set a new placeholder with the new full path (if you need it in subsequent hooks)
$myFile = $uploadpath . $filename;
$hook->setValue($sf,$myFile);
// set the permissions on the file
if (!chmod($myTarget, 0644)) {
//some debug function
}
} else {
// File not uploaded
$errorMsg = 'There was a problem uploading the file.';
$hook->addError($sf, $errorMsg);
$output = false; // generate submission error
}
*/
} else {
// File type not allowed
$errorMsg = 'Type of file not allowed.';
$hook->addError($sf, $errorMsg);
$output = false; // generate submission error
}
} else {
$hook->setValue($sf, '');
}
return $output;
Помогите дописать код, что бы была возможность загружать 2,3 или даже 5 изображений.
С уважением!