本文整理汇总了PHP中Func::generateRandomName方法的典型用法代码示例。如果您正苦于以下问题:PHP Func::generateRandomName方法的具体用法?PHP Func::generateRandomName怎么用?PHP Func::generateRandomName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func::generateRandomName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/** загрузка(сохранение/обновление) аватара
* @param integer ID записи
* @param boolean удалять предыдущий аватар
* @return имя файла успешно загруженной аватары | false
*/
function update($nRecordID, $bDeletePrevious = false, $bDoUpdateQuery = false)
{
global $oDb;
if ($nRecordID && !empty($_FILES) && $_FILES[$this->input]['error'] == UPLOAD_ERR_OK) {
$oUpload = new Upload($this->input, false);
$aImageSize = getimagesize($_FILES[$this->input]['tmp_name']);
if ($oUpload->isSuccessfull() && $aImageSize !== FALSE && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
if ($bDeletePrevious) {
$this->delete($nRecordID, false);
}
$sExtension = func::image_type_to_extension($aImageSize[2], false);
$sFilename = Func::generateRandomName($this->filenameLetters, true, true) . '.' . $sExtension;
//проверяем размер файла
if (!$oUpload->checkSize($this->maxsize)) {
return false;
}
//создаем thumbnail
$oThumb = new thumbnail($_FILES[$this->input]['tmp_name']);
$oThumb->jpeg_quality(85);
$oThumb->crop_proportionaly(1, 1, 'middle', 'center');
$oThumb->createTumbnail_if_more_then($this->path . $nRecordID . '_' . $sFilename, $this->width, $this->height, true);
@unlink($_FILES[$this->input]['tmp_name']);
if ($bDoUpdateQuery) {
$oDb->execute("UPDATE {$this->table} \n SET {$this->fieldAvatar} =" . $oDb->str2sql($sFilename) . "\n WHERE {$this->fieldID} = {$nRecordID} ");
}
return $sFilename;
}
}
return false;
}
示例2: update
/** загрузка(сохранение/обновление) скриншота
* @param integer ID записи
* @param boolean удалять предыдущий скриншот
* @return имя файла успешно загруженного скриншота | false
*/
function update($nRecordID, $bDeletePrevious = false, $bDoUpdateQuery = false)
{
global $oDb;
if ($nRecordID && !empty($_FILES) && $_FILES[$this->input]['error'] == UPLOAD_ERR_OK) {
$oUpload = new Upload($this->input, false);
$aImageSize = getimagesize($_FILES[$this->input]['tmp_name']);
if ($oUpload->isSuccessfull() && $aImageSize !== FALSE && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
if ($bDeletePrevious) {
$this->delete($nRecordID, false);
}
$sExtension = func::image_type_to_extension($aImageSize[2], false);
$sFilename = Func::generateRandomName($this->filenameLetters, true, true) . '.' . $sExtension;
//проверяем размер файла
if (!$oUpload->checkSize($this->maxsize)) {
return false;
}
//создаем thumbnail
$oThumb = new thumbnail($_FILES[$this->input]['tmp_name']);
$oThumb->jpeg_quality(85);
$bFileMoved = false;
foreach ($this->sizes as $s) {
if (!empty($s['original'])) {
$oUpload->save($this->path, $nRecordID . '_' . $s['p'] . $sFilename, false, false);
$bFileMoved = true;
break;
}
$oThumb->createTumbnail_if_more_then($this->path . $nRecordID . '_' . $s['p'] . $sFilename, $s['w'], $s['h'], isset($s['autofit']) ? $s['autofit'] : true);
}
if (!$bFileMoved) {
@unlink($_FILES[$this->input]['tmp_name']);
}
if ($bDoUpdateQuery) {
$oDb->execute("UPDATE {$this->table} \n SET {$this->fieldPreview} =" . $oDb->str2sql($sFilename) . "\n WHERE {$this->fieldID} = {$nRecordID}");
}
return $sFilename;
}
}
return false;
}
示例3: uploadImages
/**
* Загрузка файлов изображений, при помощи input=file
* @param integer ID записи
* @param integer кол-во букв в сгенерированном имени файла
* @return string имена загруженных файлов @example: '1.jpg,2.jpg' (CSV)
*/
function uploadImages($ID, $nGenerateLettersCount = 5)
{
$aFilenames = array();
if (func::isPostMethod()) {
$ID = intval($ID);
if (empty($nGenerateLettersCount)) {
$nGenerateLettersCount = 5;
}
foreach ($_FILES as $sInputName => $aFile) {
if ($aFile['name'] != '') {
$pUpload = new Upload($sInputName);
$aImageSize = getimagesize($pUpload->getFilenameUploaded());
if ($aImageSize !== FALSE && $pUpload->isSuccessfull() && in_array($aImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
$sExtension = func::image_type_to_extension($aImageSize[2], false);
$sFilename = Func::generateRandomName($nGenerateLettersCount, false, true);
$sFilenameFull = "{$sFilename}.{$sExtension}";
if ($this->saveImageFile($ID, $sFilenameFull, $pUpload, array('name' => $sFilename, 'ext' => $sExtension))) {
$aFilenames[] = $sFilenameFull;
}
}
}
}
}
if (count($aFilenames) > 0) {
$sFilenames = implode(',', $aFilenames);
}
return isset($sFilenames) ? $sFilenames : '';
}
示例4: add
function add()
{
if (!$this->haveAccessTo('edit')) {
return $this->showAccessDenied();
}
$aData = $this->input->postm(array('position' => TYPE_STR, 'cat' => TYPE_ARRAY_UINT, 'enabled' => TYPE_BOOL, 'banner_type' => TYPE_UINT, 'show_limit' => TYPE_UINT, 'resize_img' => TYPE_BOOL, 'code' => TYPE_STR, 'show_start' => TYPE_STR, 'show_finish' => TYPE_STR, 'clickurl' => TYPE_STR, 'showurl' => TYPE_STR, 'showurl_recursive' => TYPE_BOOL, 'flash_width' => TYPE_UINT, 'flash_height' => TYPE_UINT, 'flash_key' => TYPE_STR, 'title' => TYPE_STR, 'alt' => TYPE_STR, 'description' => TYPE_STR));
if (bff::$isPost) {
if (!$aData['position']) {
$this->errors->set('position');
}
if (!$this->checkRotation($aData['position'])) {
$this->errors->set('no_rotation');
}
$aData['clickurl'] = preg_replace("[^http://|www\\.|https://|ftp://]", '', $aData['clickurl']);
$aData['showurl'] = preg_replace("[^http://|www\\.|https://|ftp://]", '', $aData['showurl']);
$sFlashAddFields = '';
$sFlashAddValues = '';
if ($aData['banner_type'] == BANNERS_TYPE_FLASH) {
if (!$aData['flash_width'] || !$aData['flash_height']) {
$this->errors->set('no_flash_size');
}
$sFlashAddValues = $this->db->str2sql(serialize(array('width' => $aData['flash_width'], 'height' => $aData['flash_height'], 'key' => $aData['flash_key']))) . ', ';
$sFlashAddFields = 'flash,';
}
Func::setSESSION('banner_position', $aData['position']);
if ($this->errors->no()) {
$this->db->execute('INSERT INTO ' . TABLE_BANNERS . '
( banner_type, position, cat, clickurl, showurl, showurl_recursive, show_limit, show_start, show_finish, ' . $sFlashAddFields . ' enabled, title, alt, description)
VALUES(' . $aData['banner_type'] . ', :position, :cat, :clickurl, :showurl, ' . $aData['showurl_recursive'] . ',
' . $aData['show_limit'] . ', :show_start, :show_finish,
' . $sFlashAddValues . '
' . $aData['enabled'] . ', :title, :alt, :description)', array(':position' => $aData['position'], ':cat' => join(',', $aData['cat']), ':clickurl' => $aData['clickurl'], ':showurl' => $aData['showurl'], ':show_start' => date("Y-m-d H:i", strtotime($aData['show_start'])), ':show_finish' => date("Y-m-d H:i", strtotime($aData['show_finish'])), ':title' => $aData['title'], ':alt' => $aData['alt'], ':description' => $aData['description']));
$nRecordID = $this->db->insert_id(TABLE_BANNERS, 'id');
if ($aData['banner_type'] == BANNERS_TYPE_IMG) {
$oUpload = new Upload('bnrimg', false);
$oUpload->checkIsIMG();
if ($oUpload->isSuccessfull()) {
$aPositionInfo = $this->positions[$aData['position']];
$aImgInfo = getimagesize($_FILES['bnrimg']['tmp_name']);
$sExtension = image_type_to_extension($aImgInfo[2], false);
$sFilename = Func::generateRandomName(5, true, true) . '.' . $sExtension;
if (!isset($aPositionInfo['height']) || !$aPositionInfo['height']) {
$aPositionInfo['height'] = false;
}
if (!$aData['resize_img']) {
$aWorkingImg = array('filename' => BANNERS_PATH . $nRecordID . '_work_' . $sFilename, 'width' => $aImgInfo[0], 'height' => $aImgInfo[1], 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center');
} else {
$aWorkingImg = array('filename' => BANNERS_PATH . $nRecordID . '_work_' . $sFilename, 'width' => $aPositionInfo['width'], 'height' => $aPositionInfo['height'], 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center');
}
$aParams = array(array('filename' => BANNERS_PATH . $nRecordID . '_th_' . $sFilename, 'width' => 100, 'height' => false, 'autofit' => true, 'crop_v' => 'center', 'crop_h' => 'center'), $aWorkingImg ? $aWorkingImg : '');
$oThumb = new CThumbnail($_FILES['bnrimg']['tmp_name'], false);
$oThumb->setSaveMethod('gd');
$oThumb->save($aParams);
$this->db->execute('UPDATE ' . TABLE_BANNERS . '
SET banner=' . $this->db->str2sql($sFilename) . '
WHERE id=' . $nRecordID);
}
} elseif ($aData['banner_type'] == BANNERS_TYPE_FLASH) {
$fUpload = new Upload('flash', false);
$fUpload->save(BANNERS_PATH, $nRecordID . '_src_');
$this->db->execute('UPDATE ' . TABLE_BANNERS . '
SET banner=' . $this->db->str2sql($fUpload->getFileName()) . '
WHERE id=' . $nRecordID);
} else {
$this->db->execute('UPDATE ' . TABLE_BANNERS . '
SET banner=' . $this->db->str2sql($aData['code']) . '
WHERE id=' . $nRecordID);
}
$this->adminRedirect(Errors::SUCCESSFULL);
}
}
if (empty($aData['position'])) {
$aData['position'] = Func::SESSION('banner_position');
}
// подготавливаем линк
$aData['id_from'] = (int) $this->db->one_data('SELECT MAX(id)+1 FROM ' . TABLE_BANNERS);
if ($aData['id_from'] == 0) {
$aData['id_from']++;
}
if ($aData['id_from'] > 0) {
$aData['link'] = $this->prepareClickURL($aData['id_from']);
}
$aData['id'] = 0;
$aData['img_big'] = '';
$aData['banner'] = '';
//defaults
$aData['resize_img'] = 1;
$aData['flash'] = array('key' => '', 'width' => '', 'height' => '');
$aData['date_min'] = date('Y,n,d', mktime(0, 0, 0, date('n') - 1, date('d'), date('y')));
if (empty($aData['cat'])) {
$aData['cat'][] = 1;
}
$this->includeJS(array('datepicker'));
$this->tplAssign('aCategories', $this->getBBSCategories($aData['cat'], false));
$this->tplAssign('aPosOptions', $this->positions);
$this->tplAssign('aData', $aData);
return $this->tplFetch('admin.form.tpl');
}