Dynamic folder for file upload

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
athira
User
Posts: 12

Dynamic folder for file upload

Post by athira »

I have to store attachment based on year inside uploads folder. My primary key is not running numbers its is format like EMC-03-24-1. while row_inserting i passed this REQUEST_NO into a session variable. But it is taking in userfn as previously inserted REQUEST_NO. How to fix it? is there any alternative option to upload in a dynamic folder?


arbei
User
Posts: 9384

Post by arbei »

What did you mean by "based on year"? If "year" is a field and it always has data, you may try set the field's upload folder as $this->year->DbValue . "/". (You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.)


athira
User
Posts: 12

Post by athira »

Based on SLNO i want to upload in folder. For example i have a req with REQUEST_NO env-7-24-1 for this particular record have requested date from that date i have to take year and upload based on that year inside uploads folder


athira
User
Posts: 12

Post by athira »

this is the code inside userfn

function get_emc_date() {
	$page = CurrentPage();
	$emc_date = NULL;
	$emcno = $page->ENV_REQUEST_NO->DbValue;
	if (strlen($emcno) == 0)
		$emc_date = $page->REQUEST_DATE->DbValue;
	else
		$emc_date = ew_ExecuteScalar("SELECT REQUEST_DATE FROM env_test_req_form WHERE ENV_REQUEST_NO = '$emcno'");
	return date('Y', strtotime($emc_date));
}

in attachment filed i added this function value there inside upload folder


arbei
User
Posts: 9384

Post by arbei »

Then you may put your function in Global Code and use your function as the field's upload folder, e.g. get_emc_date() . "/".


athira
User
Posts: 12

Post by athira »

this is not working properly. i think because of the primary key not Auto Increment. It is like EMC-03-24-1. So I have to store this into session while inserting and session want to use in global code but that also not working properly. now the $emcno = $page->ENV_REQUEST_NO->DbValue; getting null. Is there any idea for that. Thank You


arbei
User
Posts: 9384

Post by arbei »

arbei wrote:

You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.

When you insert a new record, you need to make sure the field "ENV_REQUEST_NO" has value. You may use Row_Inserting event to set a value if it is not set yet.


athira
User
Posts: 12

Post by athira »

i set like this $rsnew['ENV_REQUEST_NO'] = 'EMC-'.$month.'-'.$year.'-'.$count; row_inserting it is coming correctly. bt when save into session and call inside userfn then only it is taking previous ENV_REQUEST_NO. not current one.


arbei
User
Posts: 9384

Post by arbei »

athira wrote:
i set like this $rsnew['ENV_REQUEST_NO'] = 'EMC-'.$month.'-'.$year.'-'.$count;

For exactly the same reason as:

You should not use session variable unless you are sure that the session variable will exist when you retrieve the record.

You need to make sure the same values of $month, $year, and $count exist when you retrieve the record. (You should not use current month, year and count.)


athira
User
Posts: 12

Post by athira »

then is there any option in row_inserting to save attachment in particular directory


arbei
User
Posts: 9384

Post by arbei »

Each upload field has it upload folder which you can set by $this->MyLoadField->UploadPath. However, similarly, you need to make sure you can get the same upload path when you retrieve the record. (You should not use current month, year and count.)


athira
User
Posts: 12

Post by athira »

$this->ATTACHMENT->'emc_uploads\NEW'; this is showing error


arbei
User
Posts: 9384

Post by arbei »

  1. You did not use the UploadPath property at all, and you have syntax error in your code,
  2. When you retrieve the record, you need to set the same UploadPath to the field by Row_Rendering server event.

athira
User
Posts: 12

Post by athira »

Sorry actually i did not get how to use this inside row_rendering.


Post Reply