Bonjour,
ca fait des heures que je suis dessus sans trouver la solution
j'ai un script php qui edite un fichier xml.
J'ai plusieurs champs d'upload dans un formulaire, mon probleme etant a chaque fois que j'upload un un fichier dans un des chmaps ca me suprime les infos des autre, en somme, il faut que j'upload les 5 photos d'un coup sinon si j'upload une image, puis 3 image, ma première image uploadée s'efface
merci d'avance a tous
<?php
# INITIALISATIE
ob_start();
if (!$lang) {include("../lang/french.php");}
else{
include("../lang/".$lang.".php");}
include("../includes/inc.php");
require_once("xml_connector.php");
$tpl = new TemplatePower("../skin/AdminCMS/".$skin."/mod_shop/edit.tpl");
$tpl->prepare();
$tpl->assign("skin", $skin); $tpl->assign("skin_url", "../skin/AdminCMS/".$skin."/");
$tpl->assignGlobal($L['global']);
# Lang setting
$tpl->assign("txt_tab1", $txt_tab1);
$tpl->assign("txt_tab2", $txt_tab2);
$tpl->assign("txt_tab3", $txt_tab3);
$tpl->assign("txt_tab4", $txt_tab4);
$tpl->assign("txt_tab5", $txt_tab5);
$tpl->assign("txt_tab6", $txt_tab6);
$tpl->assign("txt_tab7", $txt_tab7);
$tpl->assign("txt_tab14", $txt_tab14);
$tpl->assign("txt_tab15", $txt_tab15);
$tpl->assign("txt_tab16", $txt_tab16);
$tpl->assign("txt_tab17", $txt_tab17);
$tpl->assign("tx_back", $tx_back);
$tpl->assign("tx_global1", $tx_global1);
$tpl->assign("tx_global2", $tx_global2);
$tpl->assign("tx_global3", $tx_global3);
$tpl->assign("tx_global_tab1", $tx_global_tab1);
$tpl->assign("tx_global_tab2", $tx_global_tab2);
$tpl->assign("tx_global_tab3", $tx_global_tab3);
$tpl->assign("tx_global_tab4", $tx_global_tab4);
$tpl->assign("tx_global_tab5", $tx_global_tab5);
$tpl->assign("tx_global_tab6", $tx_global_tab6);
$tpl->assign("tx_global_tab7", $tx_global_tab7);
$tpl->assign("tx_globaladd", $tx_globaladd);
$tpl->assign("tx_globalsupress", $tx_globalsupress);
$tpl->assign("tx_globalprint", $tx_globalprint);
$tpl->assign("tx_access1", $tx_access1);
$tpl->assign("websiteurl", $websiteurl);
$tpl->assign("adminemail", $adminemail);
$tpl->assign("url_adminwebsite", $url_adminwebsite);
$tpl->assign("name_adminwebsite", $name_adminwebsite);
$tpl->assign("tx_login9", $tx_login9);
$tpl->assign("tx_login10", $tx_login10);
$tpl->assign("tx_login11", $tx_login11);
// for pagination to return to a page on which user was before
$pg = isset($_GET['pg']) ? intval($_GET['pg']) : 1;
# Query
$id = intval($_GET['id']);
$xml = new kxparse("../../_xml/products_resto.xml");
// check if this id exists
$res = $xml->search_attributes("data:product:p", "1:1:?", "id", strval($id));
if($res===FALSE)
{
redirect("index.php?pg=".$pg);
exit;
}
else
$w = $res[0];
$data = array();
if(count($_POST)>0) // form submitted
{
$data = $_POST;
$data['w'] = $xml->get_attribute("data:product:p", "1:1:$w", 'w'); // it does not come in $_POST
}
else
{
//$data['p'] = $xml->get_tag_text("data:product:p","1:1:$i");
foreach(array('n','nen','d','den','p','pjp','q','qen','s','c','m','stk','i','i2','i3','i4','i5','h1','h2','rf','subcat','p1','po','o1','o2','o3','o4','o5','o6','o7','o8','o9','o10','op1','op2','op3','op4','op5','op6','op7','op8','op9','op10','oqt1','oqt2','oqt3','oqt4','oqt5','oqt6','oqt7','oqt8','oqt9', 'mark', 'typ', 'fp') as $k)
$data[$k] = $xml->get_attribute("data:product:p", "1:1:$w", $k);
}
foreach($data as $k=>$v)
$data2[$k] = htmlspecialchars($v);
if(count($_POST)>0) // form submitted
{
$validated = true; // assume that it will pass validation
if($_FILES['i']['name']!='') // if image uploaded
{ // validate image type and extension
$tpl->assignGlobal('IMAGE_FILENAME', htmlspecialchars($_FILES['i']['name']));
if($_FILES['i']['tmp_name']=="" || $_FILES['i']['size']==0)
{
$tpl->newBlock('upload_error');
$validated = false;
}
else
{
$image_info = @getimagesize($_FILES['i']['tmp_name']);
$image_ext = pathinfo($_FILES['i']['name']);
$image_ext = strtolower($image_ext['extension']);
if(!($image_info && in_array($image_info[2], array(1 /* GIF */, 2 /* JPG */, 3 /* PNG */))))
{
$tpl->newBlock('wrong_format');
$validated = false;
}
elseif(!in_array($image_ext, array('gif','jpg','jpeg','png')))
{
$tpl->newBlock('wrong_extension');
$validated = false;
}
}
}
if($_FILES['i2']['name']!='') // if image uploaded
{ // validate image type and extension
$tpl->assignGlobal('IMAGE_FILENAME', htmlspecialchars($_FILES['i2']['name']));
if($_FILES['i2']['tmp_name']=="" || $_FILES['i2']['size']==0)
{
$tpl->newBlock('upload_error');
$validated = false;
}
else
{
$image_info = @getimagesize($_FILES['i2']['tmp_name']);
$image_ext = pathinfo($_FILES['i2']['name']);
$image_ext = strtolower($image_ext['extension']);
if(!($image_info && in_array($image_info[2], array(1 /* GIF */, 2 /* JPG */, 3 /* PNG */))))
{
$tpl->newBlock('wrong_format');
$validated = false;
}
elseif(!in_array($image_ext, array('gif','jpg','jpeg','png')))
{
$tpl->newBlock('wrong_extension');
$validated = false;
}
}
}
if($_FILES['i3']['name']!='') // if image uploaded
{ // validate image type and extension
$tpl->assignGlobal('IMAGE_FILENAME', htmlspecialchars($_FILES['i3']['name']));
if($_FILES['i3']['tmp_name']=="" || $_FILES['i3']['size']==0)
{
$tpl->newBlock('upload_error');
$validated = false;
}
else
{
$image_info = @getimagesize($_FILES['i3']['tmp_name']);
$image_ext = pathinfo($_FILES['i3']['name']);
$image_ext = strtolower($image_ext['extension']);
if(!($image_info && in_array($image_info[2], array(1 /* GIF */, 2 /* JPG */, 3 /* PNG */))))
{
$tpl->newBlock('wrong_format');
$validated = false;
}
elseif(!in_array($image_ext, array('gif','jpg','jpeg','png')))
{
$tpl->newBlock('wrong_extension');
$validated = false;
}
}
}
if($_FILES['i4']['name']!='') // if image uploaded
{ // validate image type and extension
$tpl->assignGlobal('IMAGE_FILENAME', htmlspecialchars($_FILES['i4']['name']));
if($_FILES['i4']['tmp_name']=="" || $_FILES['i4']['size']==0)
{
$tpl->newBlock('upload_error');
$validated = false;
}
else
{
$image_info = @getimagesize($_FILES['i4']['tmp_name']);
$image_ext = pathinfo($_FILES['i4']['name']);
$image_ext = strtolower($image_ext['extension']);
if(!($image_info && in_array($image_info[2], array(1 /* GIF */, 2 /* JPG */, 3 /* PNG */))))
{
$tpl->newBlock('wrong_format');
$validated = false;
}
elseif(!in_array($image_ext, array('gif','jpg','jpeg','png')))
{
$tpl->newBlock('wrong_extension');
$validated = false;
}
}
}
if($_FILES['i5']['name']!='') // if image uploaded
{ // validate image type and extension
$tpl->assignGlobal('IMAGE_FILENAME', htmlspecialchars($_FILES['i5']['name']));
if($_FILES['i5']['tmp_name']=="" || $_FILES['i5']['size']==0)
{
$tpl->newBlock('upload_error');
$validated = false;
}
else
{
$image_info = @getimagesize($_FILES['i5']['tmp_name']);
$image_ext = pathinfo($_FILES['i5']['name']);
$image_ext = strtolower($image_ext['extension']);
if(!($image_info && in_array($image_info[2], array(1 /* GIF */, 2 /* JPG */, 3 /* PNG */))))
{
$tpl->newBlock('wrong_format');
$validated = false;
}
elseif(!in_array($image_ext, array('gif','jpg','jpeg','png')))
{
$tpl->newBlock('wrong_extension');
$validated = false;
}
}
}
if($validated)
{ // update xml
if($_FILES['i']['name']!='') // if image uploaded
{ // move file to storage
$image_ext = pathinfo($_FILES['i']['name']);
$image_ext = strtolower($image_ext['extension']);
$new_image = "img".$id."_".time().".$image_ext";
$res = move_uploaded_file($_FILES['i']['tmp_name'], "../../storage/product/".$new_image);
if($_FILES['i']['name']!=''){$res = move_uploaded_file($_FILES['i'][''.$data['i'].''], "../../storage/product/".$new_image);}
$data['i'] = $new_image;
$old_image = $xml->get_attribute("data:product:p", "1:1:$w", 'i');
if($old_image!='' && $old_image!=$new_image)
unlink("../../storage/categorie/".$old_image);
}
if($_FILES['i2']['name']!='') // if image uploaded
{ // move file to storage
$image_ext = pathinfo($_FILES['i2']['name']);
$image_ext = strtolower($image_ext['extension']);
$new_image = "2_img".$id."_".time().".$image_ext";
$res = move_uploaded_file($_FILES['i2']['tmp_name'], "../../storage/product/".$new_image);
if($_FILES['i2']['name']!=''){$res = move_uploaded_file($_FILES['i2'][''.$data['i2'].''], "../../storage/product/".$new_image);}
$data['i2'] = $new_image;
$old_image = $xml->get_attribute("data:product:p", "1:1:$w", 'i2');
if($old_image!='' && $old_image!=$new_image)
unlink("../../storage/categorie/".$old_image);
}
if($_FILES['i3']['name']!='') // if image uploaded
{ // move file to storage
$image_ext = pathinfo($_FILES['i3']['name']);
$image_ext = strtolower($image_ext['extension']);
$new_image = "3_img".$id."_".time().".$image_ext";
$res = move_uploaded_file($_FILES['i3']['tmp_name'], "../../storage/product/".$new_image);
if($_FILES['i3']['name']!=''){$res = move_uploaded_file($_FILES['i3'][''.$data['i3'].''], "../../storage/product/".$new_image);}
$data['i3'] = $new_image;
$old_image = $xml->get_attribute("data:product:p", "1:1:$w", 'i3');
if($old_image!='' && $old_image!=$new_image)
unlink("../../storage/categorie/".$old_image);
}
if($_FILES['i4']['name']!='') // if image uploaded
{ // move file to storage
$image_ext = pathinfo($_FILES['i4']['name']);
$image_ext = strtolower($image_ext['extension']);
$new_image = "4_img".$id."_".time().".$image_ext";
$res = move_uploaded_file($_FILES['i4']['tmp_name'], "../../storage/product/".$new_image);
if($_FILES['i4']['name']!=''){$res = move_uploaded_file($_FILES['i4'][''.$data['i4'].''], "../../storage/product/".$new_image);}
$data['i4'] = $new_image;
$old_image = $xml->get_attribute("data:product:p", "1:1:$w", 'i4');
if($old_image!='' && $old_image!=$new_image)
unlink("../../storage/categorie/".$old_image);
}
if($_FILES['i5']['name']!='') // if image uploaded
{ // move file to storage
$image_ext = pathinfo($_FILES['i5']['name']);
$image_ext = strtolower($image_ext['extension']);
$new_image = "5_img".$id."_".time().".$image_ext";
$res = move_uploaded_file($_FILES['i5']['tmp_name'], "../../storage/product/".$new_image);
if($_FILES['i5']['name']!=''){$res = move_uploaded_file($_FILES['i5'][''.$data['i5'].''], "../../storage/product/".$new_image);}
$data['i5'] = $new_image;
$old_image = $xml->get_attribute("data:product:p", "1:1:$w", 'i5');
if($old_image!='' && $old_image!=$new_image)
unlink("../../storage/categorie/".$old_image);
}
}
if($validated)
{ // update xml
$attrs = array();
foreach(array('n','nen','d','den','p','pjp','q','qen','s','c','m','stk','i','i2','i3','i4','i5','h1','h2','rf','subcat','p1','po','o1','o2','o3','o4','o5','o6','o7','o8','o9','o10','op1','op2','op3','op4','op5','op6','op7','op8','op9','op10','oqt1','oqt2','oqt3','oqt4','oqt5','oqt6','oqt7','oqt8','oqt9', 'mark', 'typ', 'fp') as $k)
$attrs[$k] = $data[$k];
$xml->set_attributes("data:product:p", "1:1:$w", $attrs);
$xml->save();
redirect("index.php?pg=".$pg);
exit;
}
$tpl->gotoBlock('_ROOT');
}
if($data['i']=='')
$data2['i']='nopic.gif';
if($data['i2']=='')
$data2['i2']='nopic.gif';
if($data['i3']=='')
$data2['i3']='nopic.gif';
if($data['i4']=='')
$data2['i4']='nopic.gif';
if($data['i5']=='')
$data2['i5']='nopic.gif';
$tpl->assignGlobal($data2);
$tpl->assignGlobal('id', $id);
$tpl->assignGlobal('CUR_PAGE', $pg);
// fill categories drop down
$xml_cat = new kxparse("../../_xml/categories_resto.xml");
$n_cat = $xml_cat->count_tag("data:product:p", "1:1:?");
for($w=1; $w<=$n_cat; $w++)
{
$tpl->newBlock('cat');
$id = $xml_cat->get_attribute("data:product:p","1:1:$w", "id");
$tpl->assign('VAL', htmlspecialchars($id));
$tpl->assign('TITLE', htmlspecialchars($xml_cat->get_attribute("data:product:p","1:1:$w", "catfr")));
$tpl->assign('SELECTED', (isset($data['c']) && $data['c']==$id ? 'SELECTED' : ''));
}
$tpl->gotoBlock('_ROOT');
$tpl->assign('c'.intval($data['c']), 'SELECTED');
$tpl->assign('s'.intval($data['s']), 'SELECTED');
$tpl->assign('typ'.intval($data['typ']), 'SELECTED');
# TERMINATIE
$tpl->Printtoscreen();
mysql_close();
ob_end_flush();
?>
Afficher la suite