Jump to content

Where does Processwire store data?


Godfrey
 Share

Recommended Posts

Forgive me if this is a silly question, but where exactly does PW store the data that is uploaded?

I'm most curious about images. If you upload your image to the images field in PW, where does it store data for that image?

Is it in the database among the columns created? Also, does PW compress images? So if you upload 250mb of images, would that actually take up less space with PW? 

Link to comment
Share on other sites

Images are stored in /site/assets/files/1234/ where 1234 = id of the page containing that/those image(s)  :)..

The reference to the image (the image name, e.g. myimage.png) is stored in the database in a table which bears the image field name. E.g. if you created an image field in PW called photos, in the DB it will be named field_photos. That is where the image(s) name will be stored...The names and other data are stored as rows in that table. Hence, if you created an image field that can only hold 1 image, you will only see I row in the respective table. If you have an image field for multiple images, you will see multiple rows. The columns in the table help identify what image belongs to what page. The columns are:

pages_id: (whose image is this column :D. This will be equivalent to the name of the  folder in /site/assets/files/1234. In this case pages_id=1234)

data: name of the image

sort: sort order of the images; only useful when there's multiple images of course

description: self explanatory

modified: ditto

created: ditto

So how does PW know what type a field is? That information is stored in the table fields for each and every field in your site.

If this sort of thing interests you, have a look in the PW database using phpMyAdmin or similar... :). It will help you better understand the PW DB schema and the genius that it is..simple but effective.

As for image compression, I only have limited knowledge about that at present so can't answer definitively... :)

Edited by kongondo
  • Like 7
Link to comment
Share on other sites

Ah, this is very nice insight! Thanks Kongondo :)

Looking into the /site/assets/files/.... folders, it seems that PW does not do any compression, as the original-size image files are simply copied over into that folder.

Now you have me more curious; I wonder if I can modify the table so that each image includes a URL (link) column as well, beside the Description column, so that I can have each image hold a link to anywhere I want. Then for example I could do something like:
 

foreach ($albumimage as $image) {
                echo $image->link // link to some other page
                // just like how you can currently write: 
               echo $image->description
               }



.... though I'm afraid that I might have to mess around with some core scripts as well?

 

Link to comment
Share on other sites

You are welcome.

It is never advisable to mess about with the core code. I believe a module (it is not hard to create a field type, for instance) can be used to add that functionality or there could be another way of doing it via API. I am too tired to think straight now but there will be better answers here soon I know :)

Edit:

In fact, I don't see why you can't use API in your template file to output a URL with a particular image...maybe a module is an overkill in this case. I can't think; I need to sleep hehe. Let's wait for the geniuses to answer this one ;)

Edited by kongondo
  • Like 1
Link to comment
Share on other sites

Well, depending on your needs, if you are setting up a gallery of images, you could have a page tree like this:

Gallery

--Nature

--People

----Photo1

----Photo2

--Action

The template for the pages that contain the individual photos (eg Photo1, Photo2) could have the following fields:

-Title (obviously as this is required)

-Link (this is the field you are looking for)

-Photographer

-Date photo taken

-Location

-ETC

Of course this structure may be overkill for your needs, but works really well if you want a gallery type setup, so hopefully this might be of some help.

Link to comment
Share on other sites

Well as you suggested, that is more of a challenge and I expect to do it nicely would require a module to add an additional field to the image.

Ryan provides the code to do this here: http://processwire.com/talk/topic/417-extending-image-field/

A cheat's way out would be to use the description field, for both parts. This is very hackish, but will work. You could split the description field with a delimiter - maybe a pipe - eg: this is the description|http://link.tothe.image.com/

The you could use something like:

$description_link = explode("|", $image->description);

$description = $description_link[0];
$link = $description_link[1];

Depending on the client this might be too confusing for them to manage.

  • Like 1
Link to comment
Share on other sites

Kongondo, I hear you. I need some of that precious yet elusive shut-eye too ;)

So the reason I brought up the topic (Sorry this is a little off topic from the original question) was because right now for a project I am working on, I have a image slider which displays the image, the image alt attribute as a caption, and places a link over the image so that each image can link to another page. Within the plugin is an array where each element, representing the images, is an object literal with these three fields.

Using PW API to manage this slider, I simply pull the fields from a multiple images field. For each image, I output the image path, the image description for caption (the alt attribute). However, for the link of each of the images, I ended up adding a repeater field with only one field in it - a page field. So for however many images there are in the slider, you just add as many of those repeater fields. Each repeater field holds a link that corresponds with one of the images. I actually thought of doing something like your hackish method, @adrian, I just wasn't expert enough to do it :P

I think it would be nice if you could add a link property to each image in the images field, just like how there is a description property for each image (so you wouldn't have to use a hack). I was thinking of adding this as a suggestion to the roadmap. But enough of the tangent, maybe I will post this there sometime :]

Link to comment
Share on other sites

Glad you found a solution.

By chance, do the links from the slider images go to other pages on your site?

Maybe they don't, but if by chance that is the case the approach I use is a single image field in the template for the pages you want to link to. Then you can do something like:

$out .= '
<ul class="slideshow">';

foreach($pages->find('template=basic-page|another-template, slider_image!='', limit=4') as $slider){
    $out .= '<a href="'.$slider->path.'"><li><img src="'.$slider->slider_image->url.'" /></li></a>';
}

$out .= '
</ul>';
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...