Setting path to image location

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
dlee
Veteran Member
Posts: 137
Joined: 2020-04-14 00:21
Location: South Carolina, USA
Contact:

Setting path to image location

Post by dlee » 2023-01-19 19:01

I have found a way to dynamically set the path for where images are uploaded to. I needed to do this because the existing website has images in 34 different folders. Below is the changes made to config.php and /hooks/mypage.php.

This works great except for one inconvenence, after arriving on mypage_view.php theI images are blank until I refresh the page and then they all show up.

So I tried finding a way to on page load refresh the page just once; was never able to find a way to do that.

My next idea is this, there must be a function somewhere that processes the contents of the $adminConfig[] array in config.php whenever the page is loaded. Does anyone know what this function is and where it is located? My thinking is I can call the function to process $adminConfig[] within the init section of mupage.php.

If I am wrong here please tell me why so I can learn and also solve the issue of having to refresh the page in order to see the images. BTW, this Appgini app is used as the backend for the website owner to upload images, etc.

TD

Code: Select all

config.php:

<?php
	session_start();

	$dbServer = '’;
	$dbUsername = '';
	$dbPassword = '';
	$dbDatabase = '';
	$appURI = '';
	$host = 'localhost';

	$adminConfig = [

          *** other elements removed for clarity ***

		'baseUploadPath' => "images",
	];

	$fldr = $_SESSION['fdr'];
	$adminConfig['baseUploadPath'] = $fldr;

Code: Select all

/hooks/mypage.php

<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	session_start();

	function mypage_init(&$options, $memberInfo, &$args) {
		
		$_SESSION['fdr'] = 'images/gallery/mypage/';

		return TRUE;
	}


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

Re: Setting path to image location

Post by dlee » 2023-01-19 20:58

Found this solution to refresh the page just once; the following code in placed in file /hooks/footer-extras.php. Even though this solution works great for dynamically changing the image upload folder, if you see a better way to dynamically change the image upload folder I would love to see.
Thanks,
TD

Code: Select all

<script>
	/* if my "reload" var isn't set locally.. getItem will be false */
	if (!localStorage.getItem("reload")){
    		/* set reload to true and then reload the page */
   		localStorage.setItem("reload", "true");
   		 location.reload();
	}
	/* after reloading remove "reload" from localStorage */
	else {
   	 localStorage.removeItem("reload");
   	 // localStorage.clear(); // or clear it, instead
	}
	</script>

Post Reply