Creating a new Module - How can I reference an uploaded file on moodle?

Creating a new Module - How can I reference an uploaded file on moodle?

by Paul 'Fire' Preibisch -
Number of replies: 4
Hi everyone,

I am creating a new email-to-blog module which downloads emails from a pop3 server.

While parsing the email, my module will save embedded inline images as a file on the server, and then insert a row into the mdl_post table so that the email will show up as a blog entry.

I noticed that moodle references images in blog entries with a file.php?pathtoimage
structure. However, I am confused how to reference the images I will be saving to the server.

If I save all images from the blogs in /blog_images, how would I reference them?

Any help would be appreciated... thanks!
Average of ratings: -
In reply to Paul 'Fire' Preibisch

Re: Creating a new Module - How can I reference an uploaded file on moodle?

by Matt Bury -
Picture of Plugin developers
Hi Paul,

With the little knowledge of Moodle that I have, all I can tell you is that file.php is a proxy script that transfers HTTP requests to a directory, usually called moodledata, outside the publicly accessible directory (i.e. public_html, httdocs, etc.) on a server.

As soon as you upload a file via Moodle's file manager tool, it creates a new directory inside moodledata, named by the same number as the corresponding course id number.

e.g. course/view.php?id=9 // the course id is 9

therefore, files will be uploaded to this directory:

/moodledata/9/

e.g. /moodledata/9/yourfile.txt

You can reference "yourfile.txt" like this:

file.php/9/yourfile.txt

I hope this helps! smile
In reply to Matt Bury

Re: Creating a new Module - How can I reference an uploaded file on moodle?

by Paul 'Fire' Preibisch -
Thanks Matt!

What I'd like to do however, is create a module, where students blog posts can be emailed to a special email address they specify in their user settings,

Then my module will have a cron job that checks everyones special email addresses, and downoads their blog email with inline images in them. The module will then save any inline image parts as image files in the moodledata directory, and then make an entry in the mdl_post table.

My understanding is that blogs are for the entire moodle site? Or just for an individual course? If for the entire site, how can I upload their image files in an appropriate folder in order to access them later?
In reply to Paul 'Fire' Preibisch

Re: Creating a new Module - How can I reference an uploaded file on moodle?

by Matt Bury -
Picture of Plugin developers
I can't answer that question directly but what I suggest is an experiment:

Create a blog and upload and embed an image in an entry. Then try to find that image file in the moodledata directory, either in the course directory or in a user directory (this is where your avatar would be stored too).

Look in moodledata/[courseid]/...

or in moodledata/user/...

Honestly, I'm not sure where those files are stored. Perhaps someone else here knows?

Happy hunting! smile
In reply to Paul 'Fire' Preibisch

Re: Creating a new Module - How can I reference an uploaded file on moodle?

by Matt Bury -
Picture of Plugin developers
I can't answer that question directly but what I suggest is an experiment:

Create a blog and upload and embed an image in an entry. Then try to find that image file in the moodledata directory, either in the course directory or in a user directory (this is where your avatar would be stored too).

Look in moodledata/[courseid]/...

or in moodledata/user/...

Honestly, I'm not sure where those files are stored but my guess would be that they're somewhere in moodledata/user/... Perhaps someone else here knows?

Happy hunting! smile