I'm using the following code to take uploaded images and move/rename them based upon the logged in user, and the name of the record (Thank you Jane/Sergey!).
//Update contact picture
IF ($values["Cont_Picture"] <> '')
{
$values["Cont_Picture"] = str_replace("/","",$values["Cont_Picture"]);
$values["Cont_Picture"] = str_replace("'","",$values["Cont_Picture"]);
//Create directory if not exist
$filename = "files/".$_SESSION["UserID"];
IF (!file_exists($filename))
{
mkdir("files/".$_SESSION["UserID"]);
}
global $files_move;
//Save extension of uploaded file
$ext = substr(strrchr($values["Cont_Picture"], '.'), 1);
FOREACH($files_move AS $key=>$val)
{
//Move uploaded file
IF($val[0]==$_FILES["value_Cont_Picture_1"]["tmp_name"])
{
$files_move[$key][1] = "files/".$_SESSION["UserID"]."/".$values["Cont_FirstName"]." ".$values["Cont_LastName"].".".$ext;
}
}
//Rename value in the database
$values["Cont_Picture"] = $_SESSION["UserID"]."/".$values["Cont_FirstName"]." ".$values["Cont_LastName"].".".$ext;
}
This works fine until I turn on Image Resizing and Thumbnail generation. As soon as I turn those on in the visual editor, the file renaming no longer works. I'm assuming that the image processing happens before this code is even considered and this code is expecting the image to still be in the temporary location.
The image gets resized and a thumbnail is generated in the default "files" directory (or whatever you have specified in the field properties in the visual editor. Do I move the two files from here? How do I ensure the thumbnail is generated and updated in the code properly?