Hi Markr,
Thanks for clarifying.
You'll need to use the saveUploadFromFilepath function, this will create a upload record for an item based on file stored on the server:
//Get the record I'm going to copy
$oldRecord = mysql_get('old_section', '1');
//Select the uploads from the old section that belong to that record from the uploads table
$oldUploads = mysql_select('uploads', array('recordNum' => $oldRecord['num'], 'tableName' => 'old_section' ));
//prepare the record to be added to the section by removing the num value and tablename from the array
unset($oldRecord['_tableName']);
unset($oldRecord['num']);
//Insert the record into the new table, the new record number is returned
$newRecNum = mysql_insert('new_section', $oldRecord);
//Cycle through the old records uploads
foreach($oldUploads as $upload){
//Create the file path to the original upload from the CMS SETTINGS array and the uploads file name for each image
$filePath = $SETTINGS['installPath'].'/'.$SETTINGS['uploadDir'].$upload['filePath'];
//Use the the CMS save from file path function to copy the image an create a new upload record for it.
//Variables in order: section name, field name, record num, temp ID (not required here), and file path
saveUploadFromFilepath('new_section', 'upload', $newRecNum, '', $filePath);
}
Hopefully the notes above explain what's happening at each step. All of the functions used above are built into CMS Builder.
Just to clarify; I'd named the upload field for the section 'upload' in both my sections, and I'm copying a record from old_section to new_section.
Let me know if you need any help implementing this code.
Thanks!
Greg
Greg Thomas
PHP Programmer - interactivetools.com