本文整理汇总了PHP中IOHelper::getFileKind方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::getFileKind方法的具体用法?PHP IOHelper::getFileKind怎么用?PHP IOHelper::getFileKind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOHelper
的用法示例。
在下文中一共展示了IOHelper::getFileKind方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexFile
/**
* Indexes a file.
*
* @param string $uriPath The URI path fo the file to index.
*
* @return AssetFileModel|bool|null
*/
protected function indexFile($uriPath)
{
$extension = IOHelper::getExtension($uriPath);
if (IOHelper::isExtensionAllowed($extension)) {
$parts = explode('/', $uriPath);
$fileName = array_pop($parts);
$searchFullPath = join('/', $parts) . (empty($parts) ? '' : '/');
if (empty($searchFullPath)) {
$parentId = ':empty:';
} else {
$parentId = false;
}
$parentFolder = craft()->assets->findFolder(array('sourceId' => $this->model->id, 'path' => $searchFullPath, 'parentId' => $parentId));
if (empty($parentFolder)) {
return false;
}
$folderId = $parentFolder->id;
$fileModel = craft()->assets->findFile(array('folderId' => $folderId, 'filename' => $fileName));
if (is_null($fileModel)) {
$fileModel = new AssetFileModel();
$fileModel->sourceId = $this->model->id;
$fileModel->folderId = $folderId;
$fileModel->filename = $fileName;
$fileModel->kind = IOHelper::getFileKind($extension);
craft()->assets->storeFile($fileModel);
}
return $fileModel;
}
return false;
}
示例2: actionSubmitEntry
/**
* Submit Entry
*
*/
public function actionSubmitEntry()
{
$this->requirePostRequest();
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// VARIABLES
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$files = '';
$ajax = false;
$passedValidation = true;
$validationErrors = [];
$submissionErrorMessage = [];
$customSuccessMessage = '';
$customErrorMessage = '';
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$form = craft()->formBuilder2_entry->getFormByHandle(craft()->request->getPost('formHandle'));
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SUBMISSION
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$formFields = $form->fieldLayout->getFieldLayout()->getFields();
// Get all form fields
$submission = craft()->request->getPost();
// Get all values from the submitted form
$submissionData = $this->filterSubmissionKeys($submission);
// Fillter out unused submission data
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM ATTRIBUTES
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$attributes = $form->getAttributes();
$formSettings = $attributes['formSettings'];
$spamProtectionSettings = $attributes['spamProtectionSettings'];
$messageSettings = $attributes['messageSettings'];
$notificationSettings = $attributes['notificationSettings'];
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SETTINGS ||| (1) Custom Redirect, (2) File Uploads, (3) Ajax Submissions
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Custom Redirect
if ($formSettings['formRedirect']['customRedirect'] != '') {
$redirectUrl = $formSettings['formRedirect']['customRedirectUrl'];
}
// (2) File Uploads
if ($formSettings['hasFileUploads'] == '1') {
foreach ($formFields as $key => $value) {
$field = $value->getField();
switch ($field->type) {
case 'Assets':
foreach ($_FILES as $key => $value) {
if (!$value['tmp_name'] == '') {
$fileModel = new AssetFileModel();
$folderId = $field->settings['singleUploadLocationSource'][0];
$sourceId = $field->settings['singleUploadLocationSource'][0];
$fileModel->originalName = $value['tmp_name'];
$fileModel->sourceId = $sourceId;
$fileModel->folderId = $folderId;
$fileModel->filename = IOHelper::getFileName($value['name']);
$fileModel->kind = IOHelper::getFileKind(IOHelper::getExtension($value['name']));
$fileModel->size = filesize($value['tmp_name']);
if ($value['tmp_name']) {
$fileModel->dateModified = IOHelper::getLastTimeModified($value['tmp_name']);
}
if ($fileModel->kind == 'image') {
list($width, $height) = ImageHelper::getImageSize($value['tmp_name']);
$fileModel->width = $width;
$fileModel->height = $height;
}
$files[$key] = $fileModel;
}
}
break;
}
}
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM CUSTOM MESSAGES ||| (1) Success Message (2) Error Message
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Success Message
$customSuccessMessage = $messageSettings['successMessage'] ? $messageSettings['successMessage'] : Craft::t('Submission was successful.');
// (2) Error Message
$customErrorMessage = $messageSettings['errorMessage'] ? $messageSettings['errorMessage'] : Craft::t('There was a problem with your submission.');
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (3) Ajax Submissions
if ($formSettings['ajaxSubmit'] == '1') {
$this->requireAjaxRequest();
$ajax = true;
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SPAM PROTECTION ||| (1) Timed Method (2) Honeypot Method
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Timed Method
if ($spamProtectionSettings['spamTimeMethod'] == '1') {
//.........这里部分代码省略.........
示例3: _validateImage
/**
* Validates that temp file is actually an image file
*
* @param string $remoteImagePath url of remote image
* @param string $tempLocalImage file pointer to temp image
*
* @return boolean
*/
private function _validateImage($remoteImagePath, $tempLocalImage)
{
// Check to make sure the asset is an image
if (IOHelper::getFileKind(IOHelper::getExtension($tempLocalImage)) === 'image' && substr(IOHelper::getMimeType($tempLocalImage), 0, 5) === 'image') {
return true;
}
return false;
}
示例4: _mergeUploadedFiles
/**
* Merge a conflicting uploaded file.
*
* @param string $conflictResolution User response to conflict.
* @param int $theNewFileId The id of the new file that is conflicting.
* @param string $fileName The filename that is in the conflict.
*
* @return AssetOperationResponseModel
*/
private function _mergeUploadedFiles($conflictResolution, $theNewFileId, $fileName)
{
$theNewFile = $this->getFileById($theNewFileId);
$folder = $theNewFile->getFolder();
$source = craft()->assetSources->getSourceTypeById($folder->sourceId);
$fileId = null;
switch ($conflictResolution) {
case AssetConflictResolution::Replace:
// Replace the actual file
$targetFile = $this->findFile(array('folderId' => $folder->id, 'filename' => $fileName));
// If the file doesn't exist in the index, but just in the source,
// quick-index it, so we have a File Model to work with.
if (!$targetFile) {
$targetFile = new AssetFileModel();
$targetFile->sourceId = $folder->sourceId;
$targetFile->folderId = $folder->id;
$targetFile->filename = $fileName;
$targetFile->kind = IOHelper::getFileKind(IOHelper::getExtension($fileName));
$this->storeFile($targetFile);
}
$source->replaceFile($targetFile, $theNewFile);
$fileId = $targetFile->id;
// Falling through to delete the file
// Falling through to delete the file
case AssetConflictResolution::Cancel:
$this->deleteFiles($theNewFileId);
break;
default:
$fileId = $theNewFileId;
break;
}
$response = new AssetOperationResponseModel();
$response->setSuccess();
if ($fileId) {
$response->setDataItem('fileId', $fileId);
}
return $response;
}
示例5: actionSubmitEntry
/**
* Submit Entry
*
*/
public function actionSubmitEntry()
{
$form = craft()->formBuilder2_entry->getFormByHandle(craft()->request->getPost('formHandle'));
// Set Up Form Submission
$formFields = $form->fieldLayout->getFieldLayout()->getFields();
$submission = craft()->request->getPost();
$submissionData = $this->filterSubmissionKeys($submission);
// Defaults
$attributes = $form->getAttributes();
$formSettings = $attributes['formSettings'];
$spamProtectionSettings = $attributes['spamProtectionSettings'];
$messageSettings = $attributes['messageSettings'];
$notificationSettings = $attributes['notificationSettings'];
$files = '';
$errorMessage = [];
// Prepare submissionEntry for processing
$submissionEntry = new FormBuilder2_EntryModel();
// Using Ajax
if ($formSettings['ajaxSubmit'] == '1') {
$this->requireAjaxRequest();
} else {
$this->requirePostRequest();
}
// Custom Redirect
if ($formSettings['formRedirect']['customRedirect'] != '') {
$redirectUrl = $formSettings['formRedirect']['customRedirectUrl'];
}
// Spam Protection | Timed Method
if ($spamProtectionSettings['spamTimeMethod'] == '1') {
$formSubmissionTime = (int) craft()->request->getPost('spamTimeMethod');
$submissionDuration = time() - $formSubmissionTime;
$allowedTime = (int) $spamProtectionSettings['spamTimeMethodTime'];
if ($submissionDuration < $allowedTime) {
$spamMethodOne = false;
$errorMessage[] = Craft::t('You submitted too fast, you are robot!');
} else {
$spamMethodOne = true;
}
} else {
$spamMethodOne = true;
}
// Spam Protection | Honeypot Method
if ($spamProtectionSettings['spamHoneypotMethod'] == '1') {
$honeypotField = craft()->request->getPost('email-address-new');
if ($honeypotField != '') {
$spamMethodTwo = false;
$errorMessage[] = Craft::t('You tried the honey, you are robot bear!');
} else {
$spamMethodTwo = true;
}
} else {
$spamMethodTwo = true;
}
// Validate Required Fields
$validateRequired = craft()->formBuilder2_entry->validateEntry($form, $submissionData);
// File Uploads
if ($formSettings['hasFileUploads'] == '1') {
foreach ($formFields as $key => $value) {
$field = $value->getField();
switch ($field->type) {
case 'Assets':
foreach ($_FILES as $key => $value) {
if (!$value['tmp_name'] == '') {
$fileModel = new AssetFileModel();
$folderId = $field->settings['singleUploadLocationSource'][0];
$sourceId = $field->settings['singleUploadLocationSource'][0];
$fileModel->originalName = $value['tmp_name'];
$fileModel->sourceId = $sourceId;
$fileModel->folderId = $folderId;
$fileModel->filename = IOHelper::getFileName($value['name']);
$fileModel->kind = IOHelper::getFileKind(IOHelper::getExtension($value['name']));
$fileModel->size = filesize($value['tmp_name']);
if ($value['tmp_name']) {
$fileModel->dateModified = IOHelper::getLastTimeModified($value['tmp_name']);
}
if ($fileModel->kind == 'image') {
list($width, $height) = ImageHelper::getImageSize($value['tmp_name']);
$fileModel->width = $width;
$fileModel->height = $height;
}
$files[$key] = $fileModel;
}
}
break;
}
}
}
$submissionEntry->formId = $form->id;
$submissionEntry->title = $form->name;
$submissionEntry->files = $files;
$submissionEntry->submission = $submissionData;
// Process Errors
if ($errorMessage) {
craft()->urlManager->setRouteVariables(array('errors' => $errorMessage));
}
// Process Submission Entry
//.........这里部分代码省略.........
示例6: actionSaveFormEntry
public function actionSaveFormEntry()
{
$ajax = false;
$redirect = false;
$formBuilderHandle = craft()->request->getPost('formHandle');
if (!$formBuilderHandle) {
throw new HttpException(404);
}
$form = craft()->formBuilder_entries->getFormByHandle($formBuilderHandle);
if (!$form) {
throw new HttpException(404);
}
$ajaxSubmit = $form->ajaxSubmit;
$formRedirect = $form->successPageRedirect;
$formRedirectUrl = $form->redirectUrl;
if ($ajaxSubmit) {
$ajax = true;
$this->requirePostRequest();
$this->requireAjaxRequest();
} else {
$this->requirePostRequest();
}
$data = craft()->request->getPost();
$postData = $this->_filterPostKeys($data);
$formBuilderEntry = new FormBuilder_EntryModel();
$fileupload = true;
$validExtension = false;
if ($form->hasFileUploads) {
if (isset(array_values($_FILES)[0])) {
$filename = array_values($_FILES)[0]['name'];
$file = array_values($_FILES)[0]['tmp_name'];
$extension = IOHelper::getFileKind(IOHelper::getExtension($filename));
if (!in_array($extension, $this->valid_extensions)) {
$fileupload = false;
$validExtension = false;
} else {
$validExtension = true;
}
if ($validExtension) {
// Create formbuilder directory inside craft/storage if one doesn't exist
$storagePath = craft()->path->getStoragePath();
$myStoragePath = $storagePath . 'formbuilder/';
IOHelper::ensureFolderExists($myStoragePath);
$uploadDir = $myStoragePath;
// Rename each file with unique name
$uniqe_filename = uniqid() . '-' . $filename;
foreach ($_FILES as $key => $value) {
$fileUploadHandle = $key;
}
$postData[$fileUploadHandle] = $uniqe_filename;
}
}
}
$formBuilderEntry->formId = $form->id;
$formBuilderEntry->title = $form->name;
$formBuilderEntry->data = $postData;
// Use reCaptcha
$useCaptcha = $form->useReCaptcha;
if ($useCaptcha && !DEV_MODE) {
$captchaPlugin = craft()->plugins->getPlugin('recaptcha');
if ($captchaPlugin && $captchaPlugin->isEnabled) {
$captcha = craft()->request->getPost('g-recaptcha-response');
$verified = craft()->recaptcha_verify->verify($captcha);
} else {
$verified = false;
}
} else {
$verified = true;
}
// Save Form Entry
if ($verified && $fileupload && craft()->formBuilder_entries->saveFormEntry($formBuilderEntry)) {
// Save Uploaded File
if ($validExtension) {
if (move_uploaded_file($file, $uploadDir . $uniqe_filename)) {
IOHelper::deleteFile($file);
$file = $uploadDir . $uniqe_filename;
$fileModel = new AssetFileModel();
$fileModel->sourceId = $form->uploadSource;
$fileModel->folderId = $this->assetFolderId;
$fileModel->filename = IOHelper::getFileName($uniqe_filename);
$fileModel->originalName = IOHelper::getFileName($filename);
$fileModel->kind = IOHelper::getFileKind(IOHelper::getExtension($uniqe_filename));
$fileModel->size = filesize($file);
$fileModel->dateModified = IOHelper::getLastTimeModified($file);
if ($fileModel->kind == 'image') {
list($width, $height) = ImageHelper::getImageSize($file);
$fileModel->width = $width;
$fileModel->height = $height;
}
craft()->assets->storeFile($fileModel);
} else {
$fileupload = false;
}
}
// Valid extension
if ($form->notifyFormAdmin && $form->toEmail != '') {
$this->_sendEmailNotification($formBuilderEntry, $form);
}
if ($form->notifyRegistrant && $form->notificationFieldHandleName != '') {
$emailField = craft()->fields->getFieldByHandle($form->notificationFieldHandleName);
//.........这里部分代码省略.........
示例7: actionSubmitEntry
/**
* Submit Entry
*
*/
public function actionSubmitEntry()
{
$this->requirePostRequest();
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// VARIABLES
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$files = '';
$ajax = false;
$passedValidation = true;
$validationErrors = [];
$submissionErrorMessage = [];
$customSuccessMessage = '';
$customErrorMessage = '';
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$form = craft()->formBuilder2_entry->getFormByHandle(craft()->request->getPost('formHandle'));
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SUBMISSION
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$formFields = $form->fieldLayout->getFieldLayout()->getFields();
// Get all form fields
$submission = craft()->request->getPost();
// Get all values from the submitted form
$submissionData = $this->filterSubmissionKeys($submission);
// Fillter out unused submission data
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM ATTRIBUTES
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$attributes = $form->getAttributes();
$formSettings = $attributes['formSettings'];
$spamProtectionSettings = $attributes['spamProtectionSettings'];
$messageSettings = $attributes['messageSettings'];
$notificationSettings = $attributes['notificationSettings'];
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SETTINGS ||| (1) Custom Redirect, (2) File Uploads, (3) Ajax Submissions
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Custom Redirect
if ($formSettings['formRedirect']['customRedirect'] != '') {
$redirectUrl = $formSettings['formRedirect']['customRedirectUrl'];
}
// (2) File Uploads
if ($formSettings['hasFileUploads'] == '1') {
foreach ($formFields as $key => $value) {
$field = $value->getField();
switch ($field->type) {
case 'Assets':
$uploadedFiles = UploadedFile::getInstancesByName($field->handle);
$allowedKinds = [];
if ($field->settings['restrictFiles']) {
$allowedKinds = $field->settings['allowedKinds'];
}
foreach ($uploadedFiles as $file) {
$fileKind = IOHelper::getFileKind(IOHelper::getExtension($file->getName()));
if (in_array($fileKind, $allowedKinds)) {
$files[] = array('folderId' => $field->settings['singleUploadLocationSource'][0], 'sourceId' => $field->settings['singleUploadLocationSource'][0], 'filename' => $file->getName(), 'location' => $file->getTempName(), 'type' => $file->getType(), 'kind' => $fileKind);
} else {
$submissionErrorMessage[] = Craft::t('File type is not allowed!');
}
}
break;
}
}
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM CUSTOM MESSAGES ||| (1) Success Message (2) Error Message
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Success Message
$customSuccessMessage = $messageSettings['successMessage'] ? $messageSettings['successMessage'] : Craft::t('Submission was successful.');
// (2) Error Message
$customErrorMessage = $messageSettings['errorMessage'] ? $messageSettings['errorMessage'] : Craft::t('There was a problem with your submission.');
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (3) Ajax Submissions
if ($formSettings['ajaxSubmit'] == '1') {
$this->requireAjaxRequest();
$ajax = true;
}
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// FORM SPAM PROTECTION ||| (1) Timed Method (2) Honeypot Method
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// (1) Timed Method
if ($spamProtectionSettings['spamTimeMethod'] == '1') {
$formSubmissionTime = (int) craft()->request->getPost('spamTimeMethod');
$submissionDuration = time() - $formSubmissionTime;
$allowedTime = (int) $spamProtectionSettings['spamTimeMethodTime'];
if ($submissionDuration < $allowedTime) {
if ($ajax) {
$this->returnJson(['validationErrors' => [Craft::t('You submitted too fast, you are robot!')], 'customErrorMessage' => $customErrorMessage]);
} else {
$spamTimedMethod = false;
$submissionErrorMessage[] = Craft::t('You submitted too fast, you are robot!');
//.........这里部分代码省略.........