Hi there Steven,
thanks a lot for your answer.
Please correct me if I am wrong: you are suggesting me to use such functions [nufile() and nufileget.php] which rely on nuBuilderPro zzzsys_file table that stores the file within the db as a blob.
Please bear with me if would like to keep the gym db light by putting these files on a 'images' dir on the server and not as blobs on the db.
Beyond that, I could not imagine how to relate each record in the athlete table with the corresponding record in the zzzsys_file table.
To circumvent this problem, I put two objects in the form, the first being <img src="#Foto#"> HTML field, the second, an iframe pointing to a "carica" PHP code:
Code: Select all
$h = "
<html>
<body style='background-color:lightgrey'>
<form enctype='multipart/form-data' action='carica.php' method='POST'>
<input name='Foto' type='file' />
<input type='submit' value='Carica' />
</form>
</body>
</html>
";
print $h;
I therefore created a "carica.php"" file:
Code: Select all
<?php
require_once('nucommon.php');
$allowedExts = array("gif", "jpeg", "jpg", "bmp", "png");
$temp = explode(".", $_FILES["Foto"]["name"]);
$extension = end($temp);
if ((($_FILES["Foto"]["type"] == "image/gif")
|| ($_FILES["Foto"]["type"] == "image/jpeg")
|| ($_FILES["Foto"]["type"] == "image/jpg")
|| ($_FILES["Foto"]["type"] == "image/pjpeg")
|| ($_FILES["Foto"]["type"] == "image/bmp")
|| ($_FILES["Foto"]["type"] == "image/x-png")
|| ($_FILES["Foto"]["type"] == "image/png"))
&& in_array($extension, $allowedExts))
{
if ($_FILES["Foto"]["error"] > 0)
{
echo "Return Code: " . $_FILES["Foto"]["error"] . "<br>";
}
else
{
echo "Carica: " . $_FILES["Foto"]["name"] . "<br>";
echo "Tipo: " . $_FILES["Foto"]["type"] . "<br>";
echo "Dimensione: " . ($_FILES["Foto"]["size"]) . "<br>";
echo "Temporaneo: " . $_FILES["Foto"]["tmp_name"] . "<br>";
if (file_exists("images/" . $_FILES["Foto"]["name"]))
{
echo $_FILES["Foto"]["name"] . " gia esiste. ";
}
else
{
$Foto = "images/" . $_FILES["Foto"]["name"];
move_uploaded_file($_FILES["Foto"]["tmp_name"], $Foto);
echo "Caricato su: ". $Foto . "\n";
// $s = "UPDATE atleta SET Foto = '" . $Foto . "' WHERE ID = '#RECORD_ID#'"; it does not work
// print $s;
// nuRunQuery($s);
return $Foto;
}
}
}
else
{
echo "File errato";
}
?>
Till this point something works: clicking on the "Choose file" button I can pick the file and, with "Carica" button, the file is transferred to the "images" directory as expected.
The problem is now how to write path and file name in the athlete table.
I am trying several versions of Forms-Custom Code-After Save like this:
Code: Select all
$s = "UPDATE atleta SET Foto = $Foto WHERE ID = '#RECORD_ID#'";
nuRunQuery($s);
or
Code: Select all
$s = "UPDATE atleta SET Foto = '$Foto' WHERE ID = '#RECORD_ID#'";
nuRunQuery($s);
or
Code: Select all
$s = "UPDATE atleta SET Foto = '#Foto#' WHERE ID = '#RECORD_ID#'";
nuRunQuery($s);
But it does work yet.
The issue is how to pass the return value of the "carica.php" code to the form.
Here
https://www.nubuilder.net/documentation ... 2b5841457b , I found that:
"To store the file contents and information into the database we use the After Save tab on the Custom Code section of the form. On a successful upload to the server a JSON string is saved into a Hash Variable #FILES# so we can fetch the file information from this using the json_decode function from PHP."
but it seems that the referred JSON #FILES# is created by nuupload.php