我试过。。。但最终走向了完全不同的方向,因为似乎没有可行的解决方案。我结束了在临时数据库条目中的存储。如果两个人使用相同的帐户,则可能存在种族条件。但对于那些感兴趣的人,我的解决方案是:
我正在使用名为UserYourDrive的非常有效的插件作为文件上传界面。他们很友好地提供了回电,事实证明这对解决这个问题很有帮助。
我使用的是当前用户,因为他们必须登录才能执行此任务。当前用户是绑定元素。
从快捷码开始,输入:
mmd_InsertFileUploadCoreData($current_user->ID, $ListId, $RideCount, $OrderId); // straight 1st time load
但您必须确保这不是一个post响应,因此,如果没有为post设置任何内容,那么您只能调用初始核心数据,以及稍后需要的元素。
上传完成后,将收到回拨。这是存储上载文件的文件名的位置。
mmd_InsertFileUploadName($current_user->ID, $UploadedFileName); // Don\'t save it. We only have the userid to find it.
当用户单击包含其余表单数据的提交按钮时,才清除临时存储的数据。
mmd_DeleteFileUploadData($current_user->ID);
它确实存在潜在的种族条件漏洞,但这种情况应该很少发生。代码集:
add_action(\'useyourdrive_upload_post_process\', \'mmd_store_upload_information\', 10, 2); // Start watching the upload
function mmd_store_upload_information($uploaded_entries, $processor)
{
$ListId = NULL;
$OrderId = NULL;
$RideCount = NULL;
$current_user = wp_get_current_user();
$Record = mmd_FindFileUploadData($current_user->ID);
if(!empty($Record))
{
$ListId = $Record[\'ListId\'];
$OrderId = $Record[\'OrderId\'];
$RideCount = $Record[\'RideId\'];
$DBId = $Record[\'id\'];
unset($Record); // Clear the record
mmd_DebugLog(\'READ UserId: \' . $current_user->ID . \' List Id: \' . $ListId . \' OrderId: \' . $OrderId . \'Ride Count:\' . $RideCount);
}
else
return; // Nothing here, so bail out.
if($ListId == NULL || $ListId == "")
return;
if($OrderId == NULL || $OrderId == "")
return;
if($RideCount == NULL || $RideCount == "")
return;
$entries = (array)$uploaded_entries;
foreach ($entries as $cached_node)
{
$Node = (array)$cached_node;
if(empty($Node[\'name\']))
continue;
$UploadedFileName = $Node[\'name\'];
$DownloadLink = $Node[\'direct_download_link\'];
mmd_InsertFileUploadName($current_user->ID, $UploadedFileName); // Don\'t save it. We only have the userid to find it.
mmd_StoreUploadedFileName( $ListId, $OrderId, $RideCount, $UploadedFileName, $DownloadLink );
break;
}
}
function mmd_InsertFileUploadName($UserId, $FileName)
{
global $wpdb;
$Table_Name = $wpdb->prefix.\'mmd_temp_fileupload_data\';
$sql_query = $wpdb->prepare( "UPDATE $Table_Name SET FileName = %s WHERE UserId = %d", $FileName, $UserId);
$wpdb->query( $sql_query );
}
function mmd_InsertFileUploadName($UserId, $FileName)
{
global $wpdb;
$Table_Name = $wpdb->prefix.\'mmd_temp_fileupload_data\';
$sql_query = $wpdb->prepare( "UPDATE $Table_Name SET FileName = %s WHERE UserId = %d", $FileName, $UserId);
$wpdb->query( $sql_query );
}
function mmd_FindFileUploadData($UserId)
{
global $wpdb;
$Table_Name = $wpdb->prefix.\'mmd_temp_fileupload_data\';
$sql_query = $wpdb->prepare("SELECT * FROM $Table_Name WHERE UserId=%d", $UserId);
$Record = $wpdb->get_row($sql_query, ARRAY_A);
return $Record;
}
function mmd_DeleteFileUploadData($UserId)
{
global $wpdb;
$Table_Name = $wpdb->prefix.\'mmd_temp_fileupload_data\';
$sql_query = $wpdb->prepare("DELETE FROM $Table_Name WHERE UserId=%d", $UserId);
$wpdb->query( $sql_query );
}