change path to attachment files

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
artemisia
Veteran Member
Posts: 59
Joined: 2013-10-01 15:50

change path to attachment files

Post by artemisia » 2014-06-01 21:35

Currently, all attachments are uploaded into root folder on the server's appgini instance. It would be much cleaner to have a dedicated subfolder for attachments, but I don't see that option in the application. I thought of searching inside the appgini file(s) and code to customize and make this happen, but there may be some side effects that I don't know about. Can anyone point me to where I can customize the uploaded attachments location?
Thanks,
~Bob

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: change path to attachment files

Post by a.gneady » 2014-06-07 15:56

Hmm .. by default, attachments should go to the "images" folder. You can control this by editing the generated "defaultLang.php" .. Find the line starting with

Code: Select all

$Translation['ImageFolder']
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

artemisia
Veteran Member
Posts: 59
Joined: 2013-10-01 15:50

Re: change path to attachment files

Post by artemisia » 2014-06-08 00:06

I checked the path, and it's at the default you mentioned - $Translation['ImageFolder'] = './images/';
There must have been some corruption, but I fixed it by changing the path to a new folder, which worked, then reverting to /images/, which now works as expected.
Thanks for your timely reply!
~Bob

scarvalh
Posts: 3
Joined: 2016-11-08 13:31

Re: change path to attachment files

Post by scarvalh » 2017-04-15 07:16

Hi,
I'm trying to organise the images, and I'm working around and still couldn't get it.
I have a record (main table) with ex. the field "name of a person" and then a subtable with the fields "image name" and "image file"

So I would like that when I upload a specific image on the subtable that it wouldbe created as:
- first created a folder with the "name of the person" field from the main table,
- and then store the upoad the image with the name i had specify on the field "image name".

And aftwards, if I delete the record the main table, to be able to delete all the folders as well their contents.

Can anyone help on this, :)

Thks

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: change path to attachment files

Post by xbox2007 » 2018-01-14 03:06

i tell you about my project

i have table name Attachments
i save Attach files in sub folders . sub folders name by ProfileNo

you should make Attachments folder in your project folder

this code in hooks/attachments.php

Code: Select all


function Attachments_init(&$options, $memberInfo, &$args){
		global $Translation;
		// if($_REQUEST['filterer_ProfileNo']=='') $options->AllowInsert = FALSE;
		$Translation['ImageFolder'] = './Attachments/' . $_REQUEST['filterer_ProfileNo'] . "/";
		return TRUE;
	}


to view Attachment files you should make change in
templates/Attachments_templateTV.html

Code: Select all

<td id="Attachments-AttachmentFile-<%%VALUE(AttachmentID)%%>" class="Attachments-AttachmentFile text-right"><a href="link.php?t=Attachments&f=AttachmentFile&i=<%%VALUE(AttachmentID)%%>&p=<%%VALUE(ProfileNo)%%>" target="_blank" title="<%%VALUE(AttachmentFile)%%>" class="btn btn-default"><i class="glyphicon glyphicon-picture text-info"></i></a></td>
		<td id="Attachments-UploadDate-<%%VALUE(AttachmentID)%%>" class="Attachments-UploadDate text-right"><%%SELECT%%><%%VALUE(UploadDate)%%><%%ENDSELECT%%></td>

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: change path to attachment files

Post by xbox2007 » 2018-08-24 00:22

sorry i forget some code

should make change in link.php

Code: Select all

// upload paths
	$p=array(   
		'Profile' => array(
		'Attachments' => array(
			//'AttachmentFile' => $Translation['ImageFolder'],
			'AttachmentFile' => './Attachments/' . $profileNo . '/',
			'primary key' => 'AttachmentID'
		),
			//'Photo' => $Translation['ImageFolder'],
			'Photo' => './Attachments/Profile/',
			'primary key' => 'ProfileNo'
		)
	);

tomislav
Posts: 2
Joined: 2021-07-22 18:22

Re: change path to attachment files

Post by tomislav » 2021-07-26 08:26

Hi everyone,
I have been using the above code ( $Translation['ImageFolder'] = './Attachments/' . $_REQUEST['my_field1'] . "/" . $_REQUEST['my_field2'] . "/" ; ) for a long time, after the new version of AppGini 5.93. in which there was a change in settings ( Move the setting of the file upload path to the admin settings page, making it more convenient to change. ) the code no longer works.
I have tried on several variants to get it to work but to no avail. Does anyone know what would be the correct way to dynamically change the upload folder path with the new version of AppGini (from 5.93).
Thanks.

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: change path to attachment files

Post by dlee » 2021-08-20 16:56

Did you ever figure this out?
TD

tomislav
Posts: 2
Joined: 2021-07-22 18:22

Re: change path to attachment files

Post by tomislav » 2021-08-23 12:38

dlee wrote:
2021-08-20 16:56
Did you ever figure this out?
TD
Unfortunately I haven't solved the problem yet and that's why I'm not upgrading my AppGini app. I hope that someone from the forum Admin-s reads these posts and that they will offer a solution ...

dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Re: change path to attachment files

Post by dlee » 2021-08-24 03:23

Check out the things I tried in this post viewtopic.php?f=2&t=4445

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: change path to attachment files

Post by onoehring » 2021-08-27 15:17

Hi,

@scarvalh: You should probably not use a field like the name as placeholder for your path. The name might change which will lead to additional work for you. Probably it's better to use the ID as xbox2007 suggested.

@tomislav: I like the idea to change the path in the way you suggested. Maybe it does not work anymore because the language file with this variable is read - but the fields are not available at this time? Maybe it will work again, if you redefine the variable right before you need the path to save your files. But ... thinking about it, the translation file will probably be read in an AG generated file that handles the upload (can not remember where this is). So I want to suggest the following:
- Open the translation file
- Before the translation variable/array starts, make sure, you read the fields that you want to use in the current process.
- change the current translation of $Translation['ImageFolder'] accordingly in the end of the file by adding some code
Pseudo code:

Code: Select all

$Translation[.....]
// end of file

//new code starts here
unset ($_SESSION['img_folder_field1']);
unset ($_SESSION['img_folder_field2']);

// I use SESSION vars so that you can still access them from any file - in case you need to reuse them
// also (and maybe more important):
// if you want to hand over some specific value to img_folder_field1 and/or img_folder_field2, 
// you can save those in a session var and access this directly here. without querying the database
$sql_field1="SELECT somefield FROM sometable"
$_SESSION['img_folder_field1'] = sqlValue($sql_field1);

$sql_field2="SELECT someotherfield FROM someothertable"
$_SESSION['img_folder_field2'] = sqlValue($sql_field2);

// now we overwrite the "old" $Translation['ImageFolder'] from the start if the language file with the new
$Translation['ImageFolder'] = './Attachments/' . $_SESSION['img_folder_field1'] . "/" . $_SESSION['img_folder_field2'] . "/" ;
Just an idea
Olaf

Post Reply