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
7cc354f2
Commit
7cc354f2
authored
Jan 09, 2007
by
Richard Mansfield
Browse files
Make save_file static
parent
fabd7c05
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/artefact/blog/lib.php
View file @
7cc354f2
...
...
@@ -588,23 +588,22 @@ class ArtefactTypeBlogPost extends ArtefactType {
$data
=
new
StdClass
;
$data
->
title
=
$title
;
$data
->
description
=
$description
;
$data
->
owner
=
$USER
->
get
(
'id'
);
$data
->
adminfiles
=
0
;
// No admin blogs yet...
$data
->
parent
=
self
::
blogfiles_folder_id
();
$path
=
self
::
$blogattachmentroot
.
$directory
.
'/'
.
$filename
;
$f
=
new
ArtefactTypeFile
(
0
,
$data
);
$f
->
set
(
'owner'
,
$USER
->
get
(
'id'
));
$f
->
set
(
'adminfiles'
,
0
);
// No admin blogs yet...
$f
->
set
(
'parent'
,
self
::
blogfiles_folder_id
());
if
(
!
$f
->
save_file
(
self
::
$blogattachmentroot
.
$directory
.
'/'
.
$filename
))
{
$f
->
delete
();
if
(
!
$fileid
=
ArtefactTypeFile
::
save_file
(
$path
,
$data
))
{
return
false
;
}
$fileid
=
$f
->
get
(
'id'
);
$data
=
new
StdClass
;
$data
->
blogpost
=
$this
->
id
;
$data
->
file
=
$fileid
;
insert_record
(
'artefact_blog_blogpost_file'
,
$data
);
return
$fileid
;
return
true
;
}
public
static
function
blogfiles_folder_id
()
{
...
...
htdocs/artefact/blog/saveblogpost.json.php
View file @
7cc354f2
...
...
@@ -110,6 +110,6 @@ if (!empty($uploads)) {
json_reply
(
false
,
'foo'
);
json_reply
(
false
,
get_string
(
'blogpostsaved'
,
'artefact.blog'
)
);
?>
htdocs/artefact/file/lib.php
View file @
7cc354f2
...
...
@@ -282,56 +282,42 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
}
// public function save_uploaded_file($inputname) {
// require_once('uploadmanager.php');
// $um = new upload_manager($inputname);
// if ($error = $um->preprocess_file()) {
// return $error;
// }
// global $USER;
// $this->owner = $USER->get('id');
// $this->size = $um->file['size'];
// $this->dirty = true;
// $this->commit();
// // Save the file using its id as the filename, and use its id modulo
// // the number of subdirectories as the directory name.
// if ($error = $um->save_file(self::get_file_directory($this->id) , $this->id)) {
// $this->delete();
// }
// return $error;
// }
/**
* Moves a file into the myfiles area.
* Takes the name of a file outside the myfiles area.
* Returns a boolean indicating success or failure.
*/
public
function
save_file
(
$pathname
)
{
public
static
function
save_file
(
$pathname
,
$data
)
{
$dataroot
=
get_config
(
'dataroot'
);
$pathname
=
$dataroot
.
$pathname
;
if
(
!
$size
=
filesize
(
$pathname
))
{
$this
->
delete
();
return
false
;
}
if
(
empty
(
$this
->
id
))
{
$this
->
commit
();
//if (is_image($pathname)) {
if
(
false
)
{
$f
=
new
ArtefactTypeImage
(
0
,
$data
);
}
else
{
$f
=
new
ArtefactTypeFile
(
0
,
$data
);
}
$newdir
=
$dataroot
.
self
::
get_file_directory
(
$this
->
id
);
$f
->
set
(
'size'
,
$size
);
$f
->
commit
();
$id
=
$f
->
get
(
'id'
);
$newdir
=
$dataroot
.
self
::
get_file_directory
(
$id
);
check_dir_exists
(
$newdir
);
$newname
=
$newdir
.
'/'
.
$
this
->
id
;
$newname
=
$newdir
.
'/'
.
$id
;
if
(
!
rename
(
$pathname
,
$newname
))
{
$
this
->
delete
();
$
f
->
delete
();
return
false
;
}
$this
->
set
(
'size'
,
$size
);
return
true
;
return
$id
;
}
/**
* Processes a newly uploaded file, copies it to disk, and
associates it with
*
the
artefact object.
* Processes a newly uploaded file, copies it to disk, and
creates
*
a new
artefact object.
* Takes the name of a file input.
* Returns false for no errors, or a string describing the error.
*/
...
...
@@ -360,33 +346,7 @@ class ArtefactTypeFile extends ArtefactTypeFileBase {
return
$error
;
}
// /**
// * Processes a newly uploaded file, copies it to disk, creates a new artefact object and
// * associates the newly uploaded file with it.
// * Takes the name of a file input.
// * Returns a boolean indicating success or failure.
// */
// public static function uploaded_file_to_artefact_file($inputname, $data) {
// // Get the new file object first, because its id is used to
// // determine where the file goes on the filesystem
// $f = new ArtefactTypeFile(0, $data);
// require_once('uploadmanager.php');
// $um = new upload_manager($inputname);
// if (!$um->preprocess_file()) {
// return false;
// }
// $this->size = $um->file['size'];
// $this->dirty = true;
// $this->commit();
// // Save the file using its id as the filename, and use its id modulo
// // the number of subdirectories as the directory name.
// if (!$um->save_file(self::get_file_directory($this->id) , $this->id)) {
// $this->delete();
// return false;
// }
// return true;
// }
public
function
delete
()
{
if
(
empty
(
$this
->
id
))
{
return
;
...
...
htdocs/lib/uploadmanager.php
View file @
7cc354f2
...
...
@@ -93,6 +93,7 @@ class upload_manager {
function
file_is_image
()
{
// For testing only: trust the browser
return
preg_match
(
'/^image\//'
,
$this
->
file
[
'type'
]);
// Later: call a function in lib/file.php on the file.
}
/**
...
...
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