本文整理汇总了PHP中Attachment::setMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP Attachment::setMimeType方法的具体用法?PHP Attachment::setMimeType怎么用?PHP Attachment::setMimeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attachment
的用法示例。
在下文中一共展示了Attachment::setMimeType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Save this object into the database
*
* @param void
* @return boolean
* @throws DBQueryError
* @throws ValidationErrors
*/
function save()
{
$is_new = $this->isNew();
$modified_fields = $this->modified_fields;
$old_values = $this->old_values;
if ($is_new) {
$this->setType(get_class($this));
}
// if
if ($this->isModified()) {
$this->setVersion($this->getVersion() + 1);
// increment object version on save...
}
// if
db_begin_work();
$save = parent::save();
if (!$save || is_error($save)) {
db_rollback();
return $save;
}
// if
// Log activities...
if ($this->log_activities) {
if ($is_new) {
if ($this->log_creation) {
if (instance_of($this, 'File')) {
$activity_log = new NewFileActivityLog();
} else {
$activity_log = new ObjectCreatedActivityLog();
}
// if
$activity_log->log($this, $this->getCreatedBy());
}
// if
} else {
if ($this->log_update || $this->log_move_to_trash || $this->log_restore_from_trash) {
$trashed = false;
$restored = false;
if (is_array($this->modified_fields) && in_array('state', $modified_fields)) {
if (isset($old_values['state']) && $old_values['state'] == STATE_DELETED && $this->getState() == STATE_VISIBLE) {
$restored = true;
}
// if
if (isset($old_values['state']) && $old_values['state'] == STATE_VISIBLE && $this->getState() == STATE_DELETED) {
$trashed = true;
}
// if
}
// if
if ($trashed) {
if ($this->log_move_to_trash) {
$activity_log = new ObjectTrashedActivityLog();
$activity_log->log($this);
}
// if
} elseif ($restored) {
if ($this->log_restore_from_trash) {
$activity_log = new ObjectRestoredActivityLog();
$activity_log->log($this);
}
// if
} else {
if ($this->log_update) {
$activity_log = new ObjectUpdatedActivityLog();
$activity_log->log($this);
}
// if
}
// if
}
// if
}
// if
}
// if
// Pending files
if ($this->can_have_attachments && is_foreachable($this->pending_files)) {
foreach ($this->pending_files as $pending_file) {
$attachment = new Attachment();
$attachment->setParent($this);
if (isset($pending_file['created_by']) && (instance_of($pending_file['created_by'], 'User') || instance_of($pending_file['created_by'], 'AnonymousUser'))) {
$attachment->setCreatedBy($pending_file['created_by']);
} else {
$attachment->setCreatedBy($this->getCreatedBy());
}
// if
$attachment->setName($pending_file['name']);
$attachment->setLocation(substr($pending_file['location'], strlen(UPLOAD_PATH) + 1));
$attachment->setMimeType($pending_file['type']);
$attachment->setSize($pending_file['size']);
if (instance_of($this, 'File')) {
$attachment->setAttachmentType(ATTACHMENT_TYPE_FILE_REVISION);
//.........这里部分代码省略.........
示例2: Error
/**
* Creates attachment from uploaded file
*
* @param array $file
* @param ApplicationObject $parent
* @return Attachment
*/
function &make_attachment($file, $parent = null)
{
if (!isset($file) || !isset($file['tmp_name'])) {
return new Error(lang('File is not uploaded'));
}
// if
$destination_file = get_available_uploads_filename();
if (!move_uploaded_file($file['tmp_name'], $destination_file)) {
return new Error(lang('Could not move uploaded file to uploads directory'));
}
// if
$attachment = new Attachment();
$attachment->setName($file['name']);
$attachment->setLocation(basename($destination_file));
$attachment->setMimeType(array_var($file, 'type', 'application/octet-stream'));
$attachment->setSize(array_var($file, 'size', 0));
if (instance_of($parent, 'ApplicationObject')) {
$attachment->setParent($parent);
}
// if
$save = $attachment->save();
if (!$save || is_error($save)) {
@unlink($destination_file);
return $save;
}
// if
return $attachment;
}
示例3: Project
/**
* Provides logic for image picker dialog
*
* @param void
* @return null
*/
function image_picker()
{
$project_id = $this->request->get('project_id');
if ($project_id) {
$this->active_project = Projects::findById($project_id);
}
// if
if (!instance_of($this->active_project, 'Project')) {
$this->active_project = new Project();
}
// if
$image_picker_url = assemble_url('image_picker', array('project_id' => $this->active_project->getId()));
$this->smarty->assign(array('image_picker_url' => $image_picker_url, 'disable_upload' => (bool) $this->request->get('disable_upload')));
if ($this->request->isSubmitted()) {
$action = $this->request->post('widget_action');
switch ($action) {
case 'upload':
// check if any file is uploaded
$uploaded_file = array_var($_FILES, 'image', null);
if (!is_array($uploaded_file)) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('You did not uploaded any file'), true, true);
}
// if
// we are setting base attributes
$attachment = new Attachment();
$attachment->setName($uploaded_file['name']);
$attachment->setMimeType($uploaded_file['type']);
$attachment->setSize($uploaded_file['size']);
$attachment->setAttachmentType(ATTACHMENT_TYPE_ATTACHMENT);
$attachment->setCreatedBy($this->logged_user);
$attachment->setCreatedOn(new DateTimeValue());
// check if uploaded file is image
if (!$attachment->isImage()) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Uploaded file is not image'), true, true);
}
// if
$destination_file = get_available_uploads_filename();
if (!move_uploaded_file($uploaded_file['tmp_name'], $destination_file)) {
$this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Could not copy uploaded image to work folder'), true, true);
}
// if
if (FIX_UPLOAD_PERMISSION !== false) {
@chmod($destination_file, FIX_UPLOAD_PERMISSION);
}
// if
$attachment->setLocation(basename($destination_file));
$save = $attachment->save();
if (!$save || is_error($save)) {
@unlink($destination_file);
$this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getMessage(), true, true);
}
// if
echo "<img attachment_id='" . $attachment->getId() . "' src='" . $attachment->getViewUrl($this->active_project->getId()) . "' />";
die;
break;
default:
break;
}
// switch
}
// if
}