This topic is locked
[SOLVED]

Prevent Dupicate Files

9/8/2022 8:22:11 PM
PHPRunner Tips and Tricks
D
DRCR Dev author

Hi

I've searched the forums and cannot find anything related to this.

I'm trying to upload PDF invoices into PhpRunner but wanting it create an MD5 checksum for each file and store it in the database. It's essential that invoices are not imported more than once into the system.

I've tried linking php code into the app but I think I don't understand properly how that works.

Is there anything already built in that would calculate this for me?

Basically I would make the MD5 checkum field in MYSQL unique and that would prevent duplicates from ever getting into the system.

Any advice would be appreciated.

-C

Sergey Kornilov admin 9/8/2022

Implement BeforeAdd event for this table. In this event calculate md5 of the uploaded file, check if it is unique and cancel adding the record in question if such md5 value already exists there.

D
DRCR Dev author 9/8/2022

Thank you for breaking that into manageable pieces. Makes sense. This is what I have tried in Before Record Add but get a PHP error after.( Uncaught Error: Call to a member function fetchAssoc())

The php file is uploaded to table import with field invoice. The md5 is saved to field md5

$fileArray = my_json_decode($values["invoice"]);
$values["md5"] = md5($fileArray);
$dict = $values["md5"];

//********** Check if specific record exists ************

$rs = DB::Query("select md5 from import where md5 = .$dict");
$data=$rs->fetchAssoc();
if($data)

{
//********** Display a message on the Web page ************
echo "This invoice has already been uploaded";
return false;
}

else

{
return true;
}

Any advice is appreciated.