Image uploaded to 2 folders

jh

Member
Hi

I wanted to have uploaded images sent to 2 different folders. Basically I wanted to keep an original of all images in one folder (only kept as a record), and the other folder is used for details views. This is part of image editing process where I wanted to keep an original in a seperate folder.

Kind Regards
 
Hi

Thank you, Ive started to do this however I cant work out what table the image should be inserted into? That is, does it need to go into a seperate media folder somewhere or a newly created fabrik table?

Kind Regards
 
Your photos are stored in FTP and the URL to them are stored in the database table.
You can store the original file in a folder and the thumbnail in another folder.

You can create a new folder in your root for all thumbnails and within that folder you copy/paste all the folders of your images (don't copy your images, only your folder)
<img src="thumbfolder<?php if ($photo == "") {echo "nophoto.jpg;} else {echo $photo;}?>">
(result = https://yourwebsite/thumbfolder/img/photoxxxxxx.jpg)

In that way you prefix your photo with "thumbfolder" in your custom template.
 
Hi

Thank you, Ive started to do this however I cant work out what table the image should be inserted into? That is, does it need to go into a seperate media folder somewhere or a newly created fabrik table?

Kind Regards

Depends how you want your work flow. Did you want to have a second upload element in the same form that has a copy of the original?

Either way, I'd probably do this with some post-processing in a PHP form plugin. Have a plugin set to run only on new, and a second upload element in the same form. Run the plugin 'onAfterProcess', and do something like this

Code:
// fetch a copy of the row just written
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('*')->from('yourtable')->where('id = ' . (int)$formModel->formData['rowid'];
$db->setQuery($query);
$row = $db->loadObject();

// check if a file was upload ... change 'upload_element' to your (short, no table___ prefix) element name
if ($row && !empty($row->upload_element)) {
   if (JFile::exists(JPATH_SITE . $row->upload_element) {
      // get just the file name part
      $basename = basename($row->upload_element);
      // copy file
      if (JFile::copy(JPATH_SITE . $row->upload_element, JPATCH_SITE . '/relative/path/to/copy/folder/' . $basename)) {
         // if the copy worked, update the 'upload_element_copy' (or whatever it's called) element
         $row->upload_element_copy = '/relative/path/to/copy/folder/' . $basename;
         $db->updateObject('yourtable', $row, 'id');
      }
   }
}

-- hugh
 
We are in need of some funding.
More details.

Thank you.
Back
Top