Image upload path not stored in db...

edited April 2011 in Modules
I am uploading an image as part of a module I am working on and have -

$upload_path = assets_server_path('something/','images');
$fields['something_icon_upload'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE);

The file is being uploaded fine, however, when I am trying to return/render the image I am not sure of the best way to get the correct path returned. Ideally I suppose the path should be stored with the filename on db write?

Using img_path works, but I need to include the directory it was saved to again. Is this right?
Eg. in the something module...

public function show_something_icon() {
if ($this->something_icon) return 'imagesomething_icon).'" />';
}

Is there a better way for me to do this?

Comments

  • edited 4:41AM
    I couldn't add the img_path function correctly. Is there a way to comment code so that it isn't parsed in these comments?
  • edited 4:41AM
    If you wrap you content in a "code" tag, it should properly escape it.

    With regards to your question, there are a couple ways to do it.
    1. You could use a model hook to append it to the path (e.g. on_before_save()). Then in your record specific model (the model used for each record NOT the table model), you could add a method like:
    public function get_icon_path() { if ($this->icon) return img_path($this->icon); }
    2. Or you could simply just append it in your record model like so:
    public function get_icon_path() { if ($this->icon) return img_path('subfolder'.$this->icon); }
    Then you can call it in your code like so:
    <img src="<?=$my_record->icon_path?>" alt="" />
Sign In or Register to comment.