Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
454de594
Commit
454de594
authored
Oct 15, 2008
by
Richard Mansfield
Browse files
Set mime type in db when uploading files
parent
7554bafc
Changes
6
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/lib.php
View file @
454de594
...
...
@@ -625,6 +625,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$tempdir
=
self
::
$blogattachmentroot
.
$dirname
;
$result
->
error
=
$um
->
process_file_upload
(
$tempdir
,
$filename
);
$result
->
oldextension
=
$um
->
original_filename_extension
();
$result
->
filetype
=
$um
->
file
[
'type'
];
$tempfile
=
$tempdir
.
'/'
.
$filename
;
safe_require
(
'artefact'
,
'file'
);
$result
->
type
=
ArtefactTypeFile
::
detect_artefact_type
(
$tempfile
);
...
...
@@ -635,7 +636,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
/**
* Save a temporary uploaded file to the myfiles area.
*/
public
function
save_attachment
(
$directory
,
$filename
,
$
title
,
$description
,
$oldextension
,
$tags
)
{
public
function
save_attachment
(
$directory
,
$filename
,
$
uploaddata
)
{
// Create the blogfiles folder if it doesn't exist yet.
$blogfilesid
=
self
::
blogfiles_folder_id
();
...
...
@@ -648,12 +649,13 @@ class ArtefactTypeBlogPost extends ArtefactType {
safe_require
(
'artefact'
,
'file'
);
$data
=
new
StdClass
;
$data
->
title
=
$title
;
$data
->
description
=
$description
;
$data
->
tags
=
$tags
;
$data
->
title
=
$
uploaddata
->
title
;
$data
->
description
=
$
uploaddata
->
description
;
$data
->
tags
=
$
uploaddata
->
tags
;
$data
->
owner
=
$USER
->
get
(
'id'
);
$data
->
parent
=
$blogfilesid
;
$data
->
oldextension
=
$oldextension
;
$data
->
oldextension
=
$uploaddata
->
oldextension
;
$data
->
filetype
=
$uploaddata
->
filetype
;
$path
=
self
::
$blogattachmentroot
.
$directory
.
'/'
.
$filename
;
...
...
htdocs/artefact/blog/post.php
View file @
454de594
...
...
@@ -250,6 +250,8 @@ function redrawAttachList() {
// Add a newly uploaded file to the attached files list.
var uploaddata = {};
// Currently this function does not check whether names of files
// attached from my files clash with files already in the attached
// files list. This should be done here if names of attached files
...
...
@@ -279,14 +281,12 @@ function attachtopost(data) {
data.title,
data.description,
tags,
[SPAN({'style':'display: none;'}, ext),
INPUT(
{'type':'button', 'class':'button', 'value':{$getstring['remove']},
'onclick':"removefrompost('"+rowid+"')"})]
INPUT({'type':'button', 'class':'button', 'value':{$getstring['remove']}, 'onclick':"removefrompost('"+rowid+"')"})
]
)
)
);
uploaddata[rowid] = data;
redrawAttachList();
}
...
...
@@ -334,10 +334,7 @@ function saveblogpost() {
else { // uploaded file
var record = {
'id':idparts[1],
'title':scrapeText(attached.tbody.childNodes[i].childNodes[1]),
'description':scrapeText(attached.tbody.childNodes[i].childNodes[2]),
'extn':scrapeText(attached.tbody.childNodes[i].childNodes[4].childNodes[0]),
'tags':scrapeText(attached.tbody.childNodes[i].childNodes[3])
'data':uploaddata[attached.tbody.childNodes[i].id],
};
uploads.push(record);
}
...
...
htdocs/artefact/blog/saveblogpost.json.php
View file @
454de594
...
...
@@ -115,9 +115,7 @@ $uploadartefact = array();
if
(
!
empty
(
$uploads
))
{
foreach
(
$uploads
as
$upload
)
{
if
(
!
$fileid
=
$postobj
->
save_attachment
(
session_id
()
.
$createid
,
$upload
->
id
,
$upload
->
title
,
$upload
->
description
,
$upload
->
extn
,
$upload
->
tags
))
{
if
(
!
$fileid
=
$postobj
->
save_attachment
(
session_id
()
.
$createid
,
$upload
->
id
,
$upload
->
data
))
{
json_reply
(
'local'
,
get_string
(
'errorsavingattachments'
,
'artefact.blog'
));
// Things could be in a bad state.
}
...
...
htdocs/artefact/blog/upload.php
View file @
454de594
...
...
@@ -48,6 +48,7 @@ if (!$attach->error) {
$result
->
error
=
false
;
$result
->
artefacttype
=
$attach
->
type
;
$result
->
oldextension
=
$attach
->
oldextension
;
$result
->
filetype
=
$attach
->
filetype
;
$result
->
message
=
get_string
(
'uploadoffilecomplete'
,
'artefact.file'
,
$result
->
title
);
}
else
{
...
...
htdocs/artefact/file/lib.php
View file @
454de594
...
...
@@ -293,6 +293,8 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
// file is a copy of another file artefact.
protected
$fileid
;
protected
$filetype
;
// Mime type
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
parent
::
__construct
(
$id
,
$data
);
...
...
@@ -365,6 +367,7 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
'size'
=>
$this
->
get
(
'size'
),
'oldextension'
=>
$this
->
get
(
'oldextension'
),
'fileid'
=>
$this
->
get
(
'fileid'
),
'filetype'
=>
$this
->
get
(
'filetype'
),
);
if
(
$new
)
{
...
...
@@ -728,6 +731,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
}
$f
=
self
::
new_file
(
$pathname
,
$data
);
$f
->
set
(
'size'
,
$size
);
// @todo: Set mime type! (and old extension)
$f
->
commit
();
$id
=
$f
->
get
(
'id'
);
...
...
@@ -774,6 +778,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
$f
=
self
::
new_file
(
$um
->
file
[
'tmp_name'
],
$data
);
$f
->
set
(
'size'
,
$size
);
$f
->
set
(
'oldextension'
,
$um
->
original_filename_extension
());
$f
->
set
(
'filetype'
,
$um
->
file
[
'type'
]);
$f
->
commit
();
$id
=
$f
->
get
(
'id'
);
// Save the file using its id as the filename, and use its id modulo
...
...
@@ -1003,6 +1008,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
$new
->
set
(
'fileid'
,
$this
->
get
(
'fileid'
));
$new
->
set
(
'size'
,
$this
->
get
(
'size'
));
$new
->
set
(
'oldextension'
,
$this
->
get
(
'oldextension'
));
$new
->
set
(
'filetype'
,
$this
->
get
(
'filetype'
));
global
$USER
;
if
(
$new
->
get
(
'owner'
)
&&
$new
->
get
(
'owner'
)
==
$USER
->
get
(
'id'
))
{
$USER
->
quota_add
(
$new
->
get
(
'size'
));
...
...
htdocs/artefact/file/profileicons.php
View file @
454de594
...
...
@@ -165,7 +165,7 @@ $filesize = 0;
function
upload_validate
(
Pieform
$form
,
$values
)
{
global
$USER
,
$filesize
;
require_once
(
'file.php'
);
if
(
!
is_image_mime_type
(
get_mime_type
(
$values
[
'file'
][
't
mp_nam
e'
]))
)
{
if
(
!
is_image_mime_type
(
$values
[
'file'
][
't
yp
e'
]))
{
$form
->
set_error
(
'file'
,
get_string
(
'filenotimage'
));
}
...
...
@@ -211,6 +211,11 @@ function upload_submit(Pieform $form, $values) {
$artefact
->
set
(
'owner'
,
$USER
->
id
);
$artefact
->
set
(
'title'
,
(
$values
[
'title'
])
?
$values
[
'title'
]
:
$values
[
'file'
][
'name'
]);
$artefact
->
set
(
'note'
,
$values
[
'file'
][
'name'
]);
$artefact
->
set
(
'filetype'
,
$values
[
'file'
][
'type'
]);
if
(
preg_match
(
"/\.([^\.]+)$/"
,
$values
[
'file'
][
'name'
],
$saved
))
{
$artefact
->
set
(
'oldextension'
,
$saved
[
1
]);
}
$artefact
->
set
(
'size'
,
$filesize
);
$artefact
->
commit
();
$id
=
$artefact
->
get
(
'id'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment