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
info
mahara-museum
Commits
6bb29902
Commit
6bb29902
authored
Feb 14, 2007
by
Richard Mansfield
Browse files
Add original filename extensions to db on upload
parent
0c6b05fc
Changes
6
Show whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/lib.php
View file @
6bb29902
...
...
@@ -733,6 +733,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$result
=
new
StdClass
;
$tempdir
=
self
::
$blogattachmentroot
.
$dirname
;
$result
->
error
=
$um
->
process_file_upload
(
$tempdir
,
$filename
);
$result
->
oldextension
=
$um
->
original_filename_extension
();
$tempfile
=
$tempdir
.
'/'
.
$filename
;
safe_require
(
'artefact'
,
'file'
);
$result
->
type
=
ArtefactTypeFile
::
detect_artefact_type
(
$tempfile
);
...
...
@@ -743,7 +744,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
/**
* Save a temporary uploaded file to the myfiles area.
*/
public
function
save_attachment
(
$directory
,
$filename
,
$title
,
$description
)
{
public
function
save_attachment
(
$directory
,
$filename
,
$title
,
$description
,
$oldextension
)
{
// Create the blogfiles folder if it doesn't exist yet.
$blogfilesid
=
self
::
blogfiles_folder_id
();
...
...
@@ -761,6 +762,7 @@ class ArtefactTypeBlogPost extends ArtefactType {
$data
->
owner
=
$USER
->
get
(
'id'
);
$data
->
adminfiles
=
0
;
// No admin blogs yet...
$data
->
parent
=
$blogfilesid
;
$data
->
oldextension
=
$oldextension
;
$path
=
self
::
$blogattachmentroot
.
$directory
.
'/'
.
$filename
;
...
...
htdocs/artefact/blog/post.php
View file @
6bb29902
...
...
@@ -279,6 +279,7 @@ function attachtopost(data) {
if (fileattached_id(rowid) || data.error) {
return;
}
var ext = data.oldextension ? data.oldextension : '';
appendChildNodes(attached.tbody,
TR(
{'id':rowid},
...
...
@@ -288,7 +289,8 @@ function attachtopost(data) {
IMG({'src':get_themeurl('images/'+data.artefacttype+'.gif'), 'alt':data.artefacttype}),
data.title,
data.description,
[INPUT(
[SPAN({'style':'display: none;'}, ext),
INPUT(
{'type':'button', 'class':'button', 'value':{$getstring['remove']},
'onclick':"removefrompost('"+rowid+"')"}),
removehelp()]
...
...
@@ -338,7 +340,8 @@ 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])};
'description':scrapeText(attached.tbody.childNodes[i].childNodes[2]),
'extn':scrapeText(attached.tbody.childNodes[i].childNodes[3].childNodes[0])};
uploads.push(record);
}
}
...
...
htdocs/artefact/blog/saveblogpost.json.php
View file @
6bb29902
...
...
@@ -116,7 +116,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
->
title
,
$upload
->
description
,
$upload
->
extn
))
{
json_reply
(
'local'
,
get_string
(
'errorsavingattachments'
,
'artefact.blog'
));
// Things could be in a bad state.
}
...
...
htdocs/artefact/blog/upload.php
View file @
6bb29902
...
...
@@ -46,6 +46,7 @@ $attach = ArtefactTypeBlogPost::save_attachment_temporary('userfile', session_id
if
(
!
$attach
->
error
)
{
$result
->
error
=
false
;
$result
->
artefacttype
=
$attach
->
type
;
$result
->
oldextension
=
$attach
->
oldextension
;
$result
->
message
=
get_string
(
'uploadoffilecomplete'
,
'artefact.file'
,
$result
->
title
);
}
else
{
...
...
htdocs/artefact/file/lib.php
View file @
6bb29902
...
...
@@ -257,6 +257,7 @@ class ArtefactTypeFileBase extends ArtefactType {
protected
$adminfiles
=
0
;
protected
$size
;
protected
$oldextension
;
public
function
__construct
(
$id
=
0
,
$data
=
null
)
{
parent
::
__construct
(
$id
,
$data
);
...
...
@@ -300,7 +301,8 @@ class ArtefactTypeFileBase extends ArtefactType {
$data
=
(
object
)
array
(
'artefact'
=>
$this
->
get
(
'id'
),
'size'
=>
$this
->
get
(
'size'
),
'adminfiles'
=>
$this
->
get
(
'adminfiles'
)
'adminfiles'
=>
$this
->
get
(
'adminfiles'
),
'oldextension'
=>
$this
->
get
(
'oldextension'
)
);
if
(
$new
)
{
...
...
@@ -519,6 +521,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
$f
=
self
::
new_file
(
$um
->
file
[
'tmp_name'
],
$data
);
$f
->
set
(
'owner'
,
$USER
->
get
(
'id'
));
$f
->
set
(
'size'
,
$size
);
$f
->
set
(
'oldextension'
,
$um
->
original_filename_extension
());
$f
->
commit
();
$id
=
$f
->
get
(
'id'
);
// Save the file using its id as the filename, and use its id modulo
...
...
htdocs/lib/uploadmanager.php
View file @
6bb29902
...
...
@@ -191,6 +191,16 @@ class upload_manager {
}
}
public
function
original_filename_extension
()
{
if
(
isset
(
$this
->
file
)
&&
!
empty
(
$this
->
file
[
'name'
])
&&
preg_match
(
"/\.([^\.]+)$/"
,
$this
->
file
[
'name'
],
$m
))
{
return
$m
[
1
];
}
return
null
;
}
}
/**************************************************************************************
...
...
Write
Preview
Supports
Markdown
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