Undefined array key on Row Inserting event

Hi team. I tested several ways and searched in the forum, but I am not able to find a working solution for v2025.

If using a hardcoded value for the WHERE clause, the SQL works ok, but I would like to dinamically assign this value obtained from a select.

The issue I am facing is that I am receiving “Undefined array key “x_resource_type”” error when trying to execute

function Row_Inserting(?array $oldRow, array &$newRow): ?bool
{
    // Enter your code here
    // To cancel, set return value to false
    // To skip for grid insert/update, set return value to null

    // Obtain the extension for resource
    $extension = ExecuteScalar("SELECT resource_extension FROM tbl_resource_types WHERE _id = '" . AdjustSql($newRow['x_resource_type']) . "'::UUID");

    // Generate the UUID filename for the uploaded file
    GenerateFilename($newRow, "resource_path", $extension);

    return true;
}

However, on debugging info in Environment & details: - POST Data section there is the parameter x_resource_type with its correct uuid value from the database

What am I doing wrong? :thinking:

Thank you in advance :beers:

try and break out your query and echo the statement items, see if they are valid and hold the correct data…

$sSql = "SELECT resource_extension FROM tbl_resource_types WHERE _id = '" . AdjustSql($newRow['x_resource_type']) . "'::UUID");

echo $sSql ."<br>";
echo "newRow x_resource_type: ". $newRow['x_resource_type'] . "<br>";
echo "oldRow x_resource_type: ". $oldRow['x_resource_type'] . "<br>";
die();

Thank you for your answer.
Unfortunately the proposal can not work since the issue is that when calling AdjustSql($newRow['x_resource_type']) it doesn’t find the array key

I found the issue… I’ve did a print_r(get_defined_vars()) and found that when rowInserting the field’s name isn’t $newRow['x_resource_type'] but $newRow['resource_type'] so, now is taking the correct extension and aplying to the generated filename.

However I am facing another issue… :roll_eyes: Allowed file types are jpg,key,mp3,mp4,pdf,pptx. When trying to upload an jpg or a pdf file is working ok, but if I am trying to upload one of the other file types (mp3,mp4,pdf,pptx) just after finishing uploading the file (before clicking the button to save the changes) the form throws

File not found	audio.mp3

SyntaxError: Unexpected token '<', "
"... is not valid JSON

:exploding_head:

You had PHP errors, you may follow Check HTTP Response to debug. You may also see HTTP response in the debug bar, see Debugging → Ajax Data.

In Debug → Ajax Data no issue is shown.

In HTTP Response, when working, there are 3 files: blob:http:// (media), jupload (xhr) and jupload?rnd… (media API response). When failing, the third file (API response) doesn’t return.

However, I think that is some kind of a filesize issue. I tried to upload very small files (less than 2MB) and all extensions worked well. When size was bigger than 2MB with a very small amount, let’s say 2.5MB, a warning appeared saying that the filesize exceeds php.ini upload_max_filesize directive. I’ve increased the filesize in .htaccess to 64MB, to see if it works, before spending time to customize the php docker container image. It worked ok with all file sizes smaller than 10MB. However if the size is bigger than 10MB the SyntaxError: Unexpected token ‘<’, " message is thrown again…

modify the php.ini file directly

upload_max_filesize 128M

and restart the apache/web server

I think that I found the main problem.

If the file exceeds upload_max_filesize, the script throws the correct warning:

The uploaded file size exceeds the upload_max_file size directive in php.ini

If the file exceeds post_max_size the script fails with:

SyntaxError: Unexpected token '<', "
"... is not valid JSON

If the file is smaller than both params but exceeds memory_limit, the script inserts the record into the db, but the file is not uploaded and the script ends with:

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 80154216 bytes) in /var/www/html/src/phpfn.php on line 5798

Trying to upload a 500MB video file, this error was thrown. Also, the record was inserted on the DB with correct data included the generated UUID filename, but file was not uploaded to the Object Storage.

**Fatal error** : Allowed memory size of 1258291200 bytes exhausted (tried to allocate 555662024 bytes) in **/var/www/html/vendor/symfony/string/ByteString.php** on line **450**

In my case it is not feasible to adjust the value of these variables to bigger values since the upload routine will need to be able to send to the Object Storage big video files which (as of now), in some case, can even reach more than a couple of GB.

So my question now is: does PHPMaker have any way or function to split large files into chunks for uploading or do I need to create one myself and implement it?

And also, in case of big files, I think that also some max_execution_time or max_input_time can occur… :thinking:

take a look at chunked upload handling
https://www.tutorialspoint.com/how-to-upload-large-files-above-500mb-in-php

you an also search to see if there are any 3rd party scripts available…
here’s one sample, https://www.plupload.com/
https://gist.github.com/an3park/78f5c69e44298c3390b0a5e21bc707db

you will definitely have to play with the

max_xxx

variables if you are uploading files of that size

Thank you for your reccomendations. I will take a look to them. I also see that PHPMaker a 3rd party extension called FileManager which seems to deal with chunks but I didn’t used it before and I think that it needs some extra config to be able to use it and it seems that the last update was 7 years ago… :roll_eyes:

PHPMaker uses jQuery File Upload, you may want to read maxChunkSize. You may add extra options to FileUploadHandler::$options.

Hey guys, I apologize that it’s been a long time since I posted any new updates. I haven’t fixed the issue yet, but I had some personal things to sort out that were more important than upload_max_filesize :slight_smile:

I hope I will be able to do some more testing next week and share the results with you.