UPDATE: THIS worked for version 5.2 - please note that I have posted what works for version 5.3 in another posting below.
For Version 5.2
Thanks to support, user photos now make sense, for those who want to store photos in a server directory and not in the database.
The Problem: When users upload photos, the original photo name is saved. If two users have the same photo name, then the last photo writes over the first photo. You can use the date stamp feature, but I wanted to be able to look in a directory and know which photo went to which record. And with multiple photos per record, it can be really confusing.
The Quest: That each photo uploaded be automatically named after the "key column id field" and "photo field name". This would create unique names on the photo that would allow you to easily identify what record they belong to. Another benefit is when a user updates their photo the new updated photo would write over the old photo.
The Process: The "key column id field" is not created until the record is added. To have a valid "key column id field" for renaming, you need to break up the process into separate actions.
First using an Add screen have all fields you want for the record, except the photo fields.
Next when a user saves the add screen they need to be redirected to the Edit screen for that "key column id".
The Edit screen needs to have "key column id field (read only)" and your photo upload fields.
when edit screen is saved then the photos can be renamed to include the "key column id field"
The Code:
Add Page Events for After Record Added:
header("Location: );
exit();
Edit Page Events for Before Record Updated: (photo fields and READ ONLY keycolumnid field on the edit page) - Red is what you would change to your settings. Code is set up to name your photos after keycolumnid and photofield name. In my case my files are being named 12photo.jpg 12photo2.jpg and so on.
global $files_save;
[color="#008000"]// for the first photo
$ext = substr(strrchr($values[", '.'), 1);
foreach( $files_save as $key=>$val)
{
if($val["filename"]=="files/".$
FILES["value[color="#FF0000"]photofieldname_1"]["name"])
$files_save[$key]["filename"] = "files/".$oldvalues["".".$ext;
}
$values["[color="#FF0000"]photofieldname"] = $oldvalues["".".$ext;
[color="#008000"]// for the second photo field starts
$ext2 = substr(strrchr($values[", '.'), 1);
foreach( $files_save as $key=>$val)
{
if($val["filename"]=="files/".$
FILES["value[color="#FF0000"]mysecondphotofieldname_1"]["name"])
$files_save[$key]["filename"] = "files/".$oldvalues[".".$ext2;
}
$values["[color="#FF0000"]mysecondphotofieldname"] = $oldvalues[".".$ext2;
[color="#008000"]// second photo field ends
return true;
Special Thanks to Support for their help! You are great and greatly appreciated.