Hi
Is there an option where PHPMaker creates folders While uploading file.
The whole operation is:
Input box : Project → Creates folder from the input
Input box : Year-> Creates folder from the input
Upload file in Project>Year>FileThanks.
Hi
Is there an option where PHPMaker creates folders While uploading file.
The whole operation is:
Input box : Project → Creates folder from the input
Input box : Year-> Creates folder from the input
Upload file in Project>Year>FileThanks.
The option that related to upload file to folder in web server is from PHP → General Options → File Upload → Upload folder of your PHPMaker project.If you want to create another folder, then you need to create it under that Upload folder. You may use Row_Inserting and/or Row_Updating server event to create it dynamically. Simply use mkdir() PHP function.Please try it first, and you may post your code for more discussion.
I need to take the values from the Input boxes in the Add page and use the value to create new folders.
I need a way to pull the values from the input boxes.
Here is the code that I’m currently working with
if(!isset($_SESSION))
{
session_start();
}
$host = "localhost";
$user = "root";
$pass = "";
$db = 'iss';
$mysqli = mysqli_connect($host, $user, $pass, $db);
$id = 0;
$x_project_name = '';
$x_year = '';
$x_division = '';
$x_vendor = '';
$x_invoice = '';
if ($mysqli->connect_error) {
die("Connection failed: " . $mysqli->connect_error);
}
if(isset($_POST['AddBtn'])){
$project_name = $_POST['x_project_name'];
$year = $_POST['x_year'];
$division = $_POST['x_division'];
$vendor = $_POST['x_vendor'];
$invoice = $_POST['x_invoice'];
}
$mysqli->query("INSERT IGNORE INTO Invoice( project_name, year, division, vendor, invoice) VALUES ('$project_name', '$year', '$division', '$vendor', '$invoice')") or die($mysqli->error);
$curdir = getcwd();
@mkdir($curdir ."/Data/".$project_name ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year."/".$division ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year."/".$division."/".$vendor ,0777);
$_SESSION['message'] = "Record has been saved!";
$_SESSION['msg_type'] = "success";
header("location:invoice.php");
but how can I get the values from the input fields from my View?
I tried to echo the name of the input field I don’t get any values.
Thanks
nikola wrote:
I tried to echo the name of the input field I don’t get any values.
You may post your code that echo the name of the input field for more discussion.
Here is the code that I use to get the post values from the form generated by PHPMaker.
public function rowInserting($rsold, &$rsnew)
{
$id = 0;
$project_name = '';
$year = '';
$division = '';
$vendor = '';
$invoice = '';
if(isset($_POST['btn-action'])){
$project_name = $_POST['x_project_name'];
$year = $_POST['x_year'];
$division = $_POST['x_division'];
$vendor = $_POST['x_vendor'];
$invoice = $_POST['x_invoice'];
}
$curdir = getcwd();
@mkdir($curdir ."/Data/".$project_name ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year."/".$division ,0777);
@mkdir($curdir ."/Data/".$project_name."/".$year."/".$division."/".$vendor ,0777);
return true;
}
Here is the code Generated from PHPMaker in InvoiceAdd.php View file. The form is method=‘post’ the input name is name=‘x_project_name’ but still no luck can’t take the input value.
<form name="finvoiceadd" id="finvoiceadd" class="<?= $Page->FormClassName ?>" action="<?= CurrentPageUrl(false) ?>invoice.php" method="post" novalidate autocomplete="on">
<?php if (Config("CHECK_TOKEN")) { ?>
<input type="hidden" name="<?= $TokenNameKey ?>" value="<?= $TokenName ?>"><!-- CSRF token name -->
<input type="hidden" name="<?= $TokenValueKey ?>" value="<?= $TokenValue ?>"><!-- CSRF token value -->
<?php } ?>
<input type="hidden" name="t" value="invoice">
<input type="hidden" name="action" id="action" value="insert">
<input type="hidden" name="modal" value="<?= (int)$Page->IsModal ?>">
<?php if (IsJsonResponse()) { ?>
<input type="hidden" name="json" value="1">
<?php } ?>
<input type="hidden" name="<?= $Page->OldKeyName ?>" value="<?= $Page->OldKey ?>">
<div class="ew-add-div"><!-- page* -->
<?php if ($Page->project_name->Visible) { // project_name ?>
<div id="r_project_name"<?= $Page->project_name->rowAttributes() ?>>
<label id="elh_invoice_project_name" for="x_project_name" class="<?= $Page->LeftColumnClass ?>"><?= $Page->project_name->caption() ?><?= $Page->project_name->Required ? $Language->phrase("FieldRequiredIndicator") : "" ?></label>
<div class="<?= $Page->RightColumnClass ?>"><div<?= $Page->project_name->cellAttributes() ?>>
<span id="el_invoice_project_name">
<input type="<?= $Page->project_name->getInputTextType() ?>" name="x_project_name" id="x_project_name" data-table="invoice" data-field="x_project_name" value="<?PHP $Page->project_name->EditValue?>" size="30" maxlength="128" placeholder="<?= HtmlEncode($Page->project_name->getPlaceHolder()) ?>" data-format-pattern="<?= HtmlEncode($Page->project_name->formatPattern()) ?>"<?= $Page->project_name->editAttributes() ?> aria-describedby="x_project_name_help">
<?= $Page->project_name->getCustomMessage() ?>
<div class="invalid-feedback"><?= $Page->project_name->getErrorMessage() ?></div>
</span>
</div></div>
</div>
This are the buttons I used in my if statement the button with name=“btn-action”. And still don’t get any results.
<button class="btn btn-primary ew-btn" name="btn-action" id="btn-action" type="submit" form="finvoiceadd"><?= $Language->phrase("AddBtn") ?></button>
<?php if (IsJsonResponse()) { ?>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" data-bs-dismiss="modal"><?= $Language->phrase("CancelBtn") ?></button>
<?php } else { ?>
<button class="btn btn-default ew-btn" name="btn-cancel" id="btn-cancel" type="button" form="finvoiceadd" data-href="<?= HtmlEncode(GetUrl($Page->getReturnUrl())) ?>"><?= $Language->phrase("CancelBtn") ?></button>
I know that there should be a way to do this but just can’t figure it outThanks
Which code that you meant to echo the input field?
You should get the input data from the argument $rsnew.
arbei wrote:
You should get the input data from the argument > $rsnew> .
Thanks this worked perfectly with my code here is the code
$curdir = getcwd();
@mkdir($curdir ."/Data/" ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year']."/".$rsnew['division'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year']."/".$rsnew['division']."/".$rsnew['vendor'] ,0777);
Now I need to change the upload path for the files to go to their dedicated project>year>division>vendor.
I found that the path is set in src-> Config.php file. Now should I change it there or in the PHPMaker Rowinserting Event?Thanks
The path in config.php is global (for all fields), you should use server event to set your field-specific dynamic upload folder.
I’ve tried different methods and can’t make my file to go to specific folder that is created from the inputs.
Here is the code:
public function rowInserting($rsold, &$rsnew)
{
$newname = $rsnew['invoice'] = $rsnew['project_name'].$rsnew['year'].$rsnew['division'].$rsnew['vendor'].$rsnew['invoice'];
$curdir = getcwd();
@mkdir($curdir ."/Data/" ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year']."/".$rsnew['division'] ,0777);
@mkdir($curdir ."/Data/".$rsnew['project_name']."/".$rsnew['year']."/".$rsnew['division']."/".$rsnew['vendor'] ,0777);
//move_uploaded_file($invoice_tmp, $curdir."/Data/".$rsnew['project_name']."/".$rsnew['year']."/".$rsnew['division']."/".$rsnew['vendor']."/".$rsnew['invoice'].".jpg");
$olddest = $curdir."/Data/".$newname;//'C:/xampp/htdocs/issnew/Data/FullSizeRender.jpg';
$newdest= 'C:/xampp/htdocs/issnew/files/'.$newname;
//$newdest == $curdir .'/Data/'.$rsnew['project_name'].'/'.$rsnew['year'].'/'.$rsnew['division'].'/'.$rsnew['vendor'].'/'.$rsnew['invoice'];
rename($olddest, $newdest);
// Enter your code here
// To cancel, set return value to false
return true;
}
Now I have tried with move_uploaded_file but did not work then I tested the rename option it did work on the fix name file with the dynamic name from the input did not work .
The rename option does take path from $rsnew inputs. Only the file is not recognized.
This is wrong: $newdest= ‘C:/xampp/htdocs/issnew/files/’.$newname;Your upload folder must be relative to your root folder. You may read documentation regarding this.
Yes, I know but my needs are to copy the upload files in the folder that will be created when row inserting function is called.
Ex.
$rsnew[‘project_name’]->$rsnew[‘year’]->$rsnew[‘division’]->$rsnew[‘vendor’]->The file here.pdf
Note that when Row_Inserting server event is fired, the uploaded file is not in your specified path ($olddest), so your code rename($olddest, $newdest) won’t work.To get the temp path of the uploaded file, you may use $this->MyFileUploadField->Upload->getTempFile() (replace the field name with your real one, assume singe file upload).