我有3对文本框,它的文件输入文本框列出了用户上传的文件。最后一对是空白的(用户尚未上传任何文件)。
比方说,用户上传了一个新文件以更新第一对,并选择一个新文件插入最后一对,我如何与下面的代码区分开来何时更新和何时插入。
非常感谢您的帮助。谢谢
$target_path = "upload/doc_client_document/";
if(isset($_FILES['docUpload']))
{
$CLIENT_PROJET_ID = $_POST['TXTCLIENT_PROJET_ID'];
$CLIENT_ID = $_POST['TXTCLIENT_ID'];
$PROJET_ID = $_POST['TXTPROJET_ID'];
foreach($_FILES['docUpload']["name"] AS $key=>$file)
{
$DOC_CLIENT_ID = $key;
//echo "<pre>";print_r($file);echo "</pre>";
foreach($file AS $keyz=>$filez)
{
$CLIENT_PROJET_DOC_CLIENT_ID = $keyz;
//echo "<pre>";print_r($filez);echo "</pre>";echo "<br>";
$filezx = $filez["'docUpload'"];
$file = $_FILES['docUpload']['name'][$key][$keyz]["'docUpload'"];
$file_tmp = $_FILES['docUpload']['tmp_name'][$key][$keyz]["'docUpload'"];
$file_name = basename($file);
//move_uploaded_file($file_tmp, $target_path. $file);
if(move_uploaded_file($file_tmp, $target_path. $file))
{
$DOC_CLIENT_NOM = $target_path.$file;
//echo "<pre>";print_r($DOC_CLIENT_NOM);echo "</pre>";
//echo "<pre>";print_r($docfiles);echo "</pre>";
//echo "<pre>";print_r($filez["'docUpload'"]);echo "</pre>";echo "<br>";
if(isset($DOC_CLIENT_NOM) && $DOC_CLIENT_NOM <> "" && $keyz["'docUpload'"] <> "")
{
$tableProjetTaches = new table("client_projet_doc_client");
$tableProjetTaches -> set('CLIENT_PROJET_ID', $CLIENT_PROJET_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_ID', $CLIENT_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('PROJET_ID', $PROJET_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('DOC_CLIENT_ID', $DOC_CLIENT_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_MODELE_DOC', $DOC_CLIENT_NOM, PDO::PARAM_STR);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_USER_ID', $userId, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_DATE_CREATION', date('Y-m-d H:i:s'), PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_DATE_MAJ', date('Y-m-d H:i:s'), PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_STATUT', 1, PDO::PARAM_INT);
if ($tableProjetTaches->insert())
$success = 'Ajout réussie.';
}
else
{
$tableProjetTaches = new table("client_projet_doc_client");
$tableProjetTaches -> set('CLIENT_PROJET_ID', $CLIENT_PROJET_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_ID', $CLIENT_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('PROJET_ID', $PROJET_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('DOC_CLIENT_ID', $DOC_CLIENT_ID, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_MODELE_DOC', $DOC_CLIENT_NOM, PDO::PARAM_STR);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_USER_ID', $userId, PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_DATE_CREATION', date('Y-m-d H:i:s'), PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_DATE_MAJ', date('Y-m-d H:i:s'), PDO::PARAM_INT);
$tableProjetTaches -> set('CLIENT_PROJET_DOC_CLIENT_STATUT', 1, PDO::PARAM_INT);
$condition = array('CLIENT_PROJET_DOC_CLIENT_ID = ' . $keyz);
if ($tableProjetTaches->update($condition))
$success = 'Modification service réussie.';
}
}
}
}
}