I'm using Uploadify as part of a form. Let me give you a bit of background, it may help. I have a form where a user can add "projects" to a website. First they type in the name of the project and a description. On submit, this updates a PHP/MySQL database table named "project" and is given an ID.
The user can then upload files to a location on the server. I wish to add the project name onto the start of the file name for upload AND the project ID (which I need to add to the database) before upload begins, then when upload completes add the file details to a database table "image" - linked to "project" via the project ID.
I know I'm kinda bouncing back and forth a lot, I need to know how to do this. Two database tables to update, one on form submit and one on file-upload. I need to pass the project name and ID to the uploadify upload script.
SOLUTION:
I had to use the below uploadify method to send the Project ID to the uploadify script, having previously filled variable pid with the mysql_insert_id result:
'onSelectOnce': function(event,data) {
$('#file_upload').uploadifySettings('scriptData', {'pid': pid});
}
I could then receive the pid variable in the PHP uploadify script using a simple post:
$pid = $_POST['pid'];
It was then a matter of running a select within this script to get the data I needed for the database (the project alias) and adding it to the filename before upload:
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/' . $alias . '-';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
Hopefully this will help people in the future.