Uploader un tableau sur serveur

Zonzorg - Modifié le 20 sept. 2020 à 19:24
 Zonzonrg - 21 sept. 2020 à 20:23
Bonjour,
je cherche a convertir un array annee[] vers un fichier a uploader sur un serveur.
j'ai beau chercher je tombe toujours sur "move_uploaded_file($_FILES["xxxx"]["tmp_name"], $target);"
c'est un peu nebuleux pour moi je ne comprend pas d'ou vient le ["tmp_name"]
c'est un script pour faire des reservation de location sur un octet ou chaque location 1 ou 0
(occupe ou libre) (voir source) ( annee[jour de l'annee]>>location)&1)

si quelqu'un pourrai me remplir "function save_binary_resource() "
cela serai sympa merci.



<html>
<head>
<title>Calendrier de Location</title>
<style type="text/css">

body {
color:black;
background-color:white;
background-image:url(background.jpg);
}

.main {
width:200px;
border:1px solid black;
}

.main1 {
width:200px;
border:1px solid black;
background-color:#0689BB;
font:bold 12px verdana;
color:white;
}

.month {
background-color:#0689BB;
font:bold 12px verdana;
color:white;
}

.daysofweek {
background-color:#EBEBEB;
font:bold 12px verdana;
color:Black;
}

.days {
font-size: 12px;
font-family:verdana;
color:black;
background-color: #CAFCC9;
padding: 2px;
}

.occupe {
font-size: 12px;
font-family:verdana;
color:black;
background-color: #D0023D;
padding: 2px;
}

.occupe1 {
font-size: 12px;
font-family:verdana;
color:#4F4F4F;
background-color: #DB84A4;
padding: 2px;
}

.hdays {
font-size: 12px;
font-family:verdana;
color: #9F9F9F;
background-color: #C8C8F8;
padding: 2px;
}

.days #today{
font-weight: bold;
color: red;
}

.occupe #today{
font-weight: bold;
color: white;
}

body {margin:0px}
#af {text-align:center}

</style>

<script type="text/javascript">

var Locations=["Location 1","Location 2","Location 3","Location 4","Location 5","Location 6","Location 7","Location 8"];
var LesMois=["Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septempbre","Octobre","Novembre","Decembre"];
var LesJours=["Lu","Ma","Me","Je","Ve","Sa","Di",'Se']; 
var Jdmois=[31,28,31,30,31,30,31,31,30,31,30,31];
var annee= Array(366);


function load_binary_resource(url) {
  var byteArray = [];
  var req = new XMLHttpRequest();
  req.open('GET', url, false);
  req.overrideMimeType('text\/plain; charset=x-user-defined');
  req.send(null);
  if (req.status != 200) {
   byteArray.length=366;
   byteArray.fill(0,0,byteArray.length);
  }
  else
  for (var i = 0; i < req.responseText.length; ++i) byteArray.push(req.responseText.charCodeAt(i) & 0xff);
  return byteArray;
};

function No_sem(A,M) {
var ddate=new Date();
 ddate.setYear(A);
 ddate.setMonth(M);
 ddate.setDate(1);
 date2=new Date(A,0,1); 
 quantieme = Math.trunc((ddate.getTime() - date2.getTime()) / (24 * 60* 60 * 1000)); // quantieme: numero du jour du 1er jour du mois 
 date2=new Date(A,0,1); 
 if ((M==0)&&(date2.getDay()!=1)) { // le nombre de semaine de l'annee precedente (pour le mois de janvier) et si le 1er jour n'est pas un lundi
  ddate.setYear(A-1);
  ddate.setMonth(11);
  ddate.setDate(31);
  date2=new Date(A-1,0,1);
 } 
 x=1; //Cherche le premier Lundi de l'année
 do
 {
  date2.setDate(x);
  x++;
 }
 while(date2.getDay()!=1);
 temps=ddate.getTime()-date2.getTime();
 sem=temps / (24 * 60 * 60 * 1000 * 7); 
 nosemaine=Math.trunc(sem+1);
};

function buildCal(m, y, cM, cH, cDW, hD, brdr){
 
var date = new Date(y, m-1, 1); 
 date.od=(date.getDay()+6)%7+1;
var todaydate=new Date() 
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added
 Jdmois[1]=(((date.getFullYear()%100!=0)&&(date.getFullYear()%4==0))||(date.getFullYear()%400==0))?29:28;
var calendrier='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
 calendrier+='<td colspan="8" align="center" class="'+cH+'">'+LesMois[m-1]+'</td></tr><tr align="center">';
 for (s=0;s<8;s++) 
 if (s==7) calendrier+='<td class="'+cH+'">'+LesJours[s]+'</td>'; 
 else calendrier+='<td class="'+cDW+'">'+LesJours[s]+'</td>'; 
 calendrier+='</tr><tr align="center">';
 No_sem(y,m-1); // quantieme: numero du jour du 1er jour du mois - nosemaine : numero de la semaine du 1er jour du mois
 for (i=1;i<=42;i++) {
 var x=((i-date.od>=0)&&(i-date.od<Jdmois[m-1]))? i-date.od+1 : 0;
 v=x;
 if (x==0) { 
  if (i<7) {
   if (m>1) {
    v=Jdmois[(m+10)%12]+i-date.od+1 ;
    g=quantieme+v-Jdmois[(m+10)%12]-1;
    if (((annee[g]>>selectElem)&1)==0) calendrier+='<td class="'+hD+'">'+v+'</td>'; 
    else calendrier+='<td class="occupe1">'+v+'</td>';
   }
  else calendrier+='<td class="'+hD+'"> </td>';;
  }
 else {
   v=i-date.od-Jdmois[(m+11)%12]+1;
   calendrier+='<td class="'+hD+'">'+v+'</td>';
  }
 } 
 else 
 {
  if (x==scanfortoday) v='<span id="today">'+x+'</span>' //DD added
  if (((annee[quantieme+x-1]>>selectElem)&1)==0) calendrier+='<td class="days">'+v+'</td>'; 
  else calendrier+='<td class="occupe">'+v+'</td>'; 
 }
 if ((i)%7==1)  t=i-date.od+1-Jdmois[m-1];
 if((i)%7==0)
  {  
 if (t>0) calendrier+='<td class="'+hD+'"> </td></tr><tr align="center">';
  else
  {
//  calendrier+='<td class="'+cH+'">'+nosemaine+'</td></tr><tr align="center">';
  if ((nosemaine>51)&&(m==1)) e=0; else e=nosemaine;
  if (Lundi1==0) e-=1;
  calendrier+='<td class="'+cH+'"><input type="button" style="background-color:transparent; width:100%;" value="'+nosemaine+'" onclick="action('+e+')" " /></td></tr><tr align="center">';
  if ((nosemaine>51)&&(m==1)) nosemaine=1; else nosemaine++;
  }
 }
}
return calendrier+='</tr></table></div>';
}

function calendrier(y, cM, cH, cDW, hD, brdr){
//  document.getElementById("changeimg").style='background-image: url(background'+selectElem+'.jpg);';
 document.getElementById("af4").firstChild.data='"'+Locations[selectElem]+'"';
 if(y>=2019 && y<=2060) document.getElementById("af3").firstChild.data=y;
 while (document.getElementById("af1").lastChild) document.getElementById("af1").removeChild(document.getElementById("af1").lastChild);
 newHTML = '<table align="center" border="0" cellspacing="0" cellpadding="3">';
 for (j=0;j<6;j++) {
 newHTML+= '</tr>';
 for (m=1;m<3;m++) {newHTML+= '<td>'+buildCal(m+j*2, y, cM, cH, cDW, hD, brdr)+'</td>' }
 newHTML+= '</tr>';
 }
 newHTML+= '</table>';
 document.getElementById("af1").innerHTML = newHTML;
 
}

function init(){
    nHTML= '<table style="font-size:9">';
 for (i=0;i<Locations.length;i++) 
 nHTML+= '<p><Div><input type="button" style="width:157px; height:40px" value="'+Locations[i]+'" style="height:32px" onclick="calrefresh('+i+');"></div></p>';
 nHTML+= '<p><Div><input type="button" style="width:157px; height:40px" value="sauve annee" style="height:32px" onclick="save_binary_resource();"></div></p>';
 nHTML+= '</table>';
 document.getElementById("af5").innerHTML = nHTML;
  annee.fill(0,0,366);
}

function remplirsem(y,sema,occ) {
 if (Lundi1==0) sema-=1;
 if (sema>=0) 
 for (i=0;i<7;i++) {
  q=sema*7+i-Lundi1;
 if (q>=0) annee[q]=occ;
 }
}
function getRandomInt(max) {
  return Math.trunc(Math.random() * max);
}
function loadannee(y) { 
var date2 = new Date(y, 0, 1); 
 Lundi1=(date2.getDay()+6)%7;
//annee=load_binary_resource(y+'.bin'); // Fichier du serveur (2020.bin)
    annee.fill(0,0,366);
 for (x=0;x<53;x++) {
  b=getRandomInt((1<<(Locations.length))-1);
  remplirsem(y,x,b);
 }
// remplirsem(y,15);/**/
}

function calrefresh(sel) {
 selectElem=sel;
 calendrier(curyear, 'main', 'month', 'daysofweek', 'hdays', 1); 
}

function action(SelSema) {
  if (SelSema==0) q=0; else
  q=SelSema*7-Lundi1;
  z=(~(annee[q])>>selectElem)&1;
 for (i=0;i<7;i++) {
  q=SelSema*7+i-Lundi1;
//  z=(~(annee[q])>>selectElem)&1;
  if ((q>=0)&&(q<annee.length))
  {  
   if (z==0) annee[q]=annee[q] & ((~(1<<selectElem))&255)
   else annee[q]=annee[q]|(1<<selectElem);
  }
 }
 calrefresh(selectElem);
}

function save_binary_resource(){
alert(curyear);
  }



</script> 

</head>

<script type="text/javascript">

var todaydate=new Date()
var curmonth=todaydate.getMonth()+1 //get current month (1-12)
var curyear=todaydate.getFullYear() //get current year
var SelSema=0;
var selectElem=0;


</script>

<body onload="init(curyear); loadannee(curyear);calrefresh(selectElem);">
<table style="font-size:9">
  <tbody>
    <tr>
      <td style="text-align: left; height: 150px; "></td>
      <td colspan="1" rowspan="2" id="changeimg" ">
          <table style='font-size:9'>
   <div id="af">
    <p style="padding-top:20px">
    <strong style='font-size:19'>Réservation</strong>
    </p>
    <p>
    <strong id="af4" style='font-size:19'>?</strong>
    </p>
    <p style="padding-top:20px">
     <input type="button" value="<<" onclick="if(curyear>2019){curyear-=1; loadannee(curyear); calrefresh(selectElem)}" />
     <strong id="af3" style='font-size:19'>?</strong>
     <input type="button" value=">>" onclick="if(curyear<2060){curyear++; loadannee(curyear); calrefresh(selectElem)}" />
    </p>
   </div>
   <div id="af1">?</div>
  </table>
   </td>
      <td colspan="1" rowspan="2"> 
  <div> 
     <table class="main" cols="4" cellpadding=0 border=1 cellspacing="0" >
        <tbody>
          <tr align="center">
            <td colspan=2 class="month">Legende</td>
          </tr>
          <tr align="center">
            <td class="occupe"></td>
            <td class="daysofweek">Réservé</td>
          </tr>
          <tr align="center">
            <td class="days"></td>
            <td class="daysofweek">Libre</td>
          </tr>
        </tbody>
      </table>
   </div>
   <p>
   <Div>
   <table class="main" cols="4" cellpadding=0 border=1 cellspacing="0">
        <tbody>
          <tr align="center">
            <td class="month">Prix de la semaine</td>
          </tr>
          <tr align="center">
            <td class="daysofweek">xxx,xx €/semaine</td>
          </tr>
          <tr align="center">
            <td class="daysofweek">xxx,xx €/ hors saison</td>
          </tr>
        </tbody>
      </table>
   </Div>
   <div style='font-size:15' align="center" >
   <p><strong>
   Contact location:<br>
   ***@***<br><br>
   (c) Zonzorg 2020<br>
   </strong>
   </p>
   </div>
 </td>
    </tr>
    <tr>
  <Td align="center" style="vertical-align:top" id='af5'></td>
    </tr>
  </tbody>
</table>
</body>
</html>

1 réponse

j'ai utiliser ça:
fichier Example1.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<script>

var annee= Array(366);
 annee.fill(0,15,annee.length);
 
</script>
<body>

<!DOCTYPE html>
<html>
   <head>
   </head>
<body>
   <form action="upload2.php" method="POST" enctype="multipart/form-data">
      <input type="submit">
   </form>
</body>
<html>

</html>


puis upload2.php:
<?php
$fp = fopen('data.bin', 'w');
for ($i=0;$i<366;$i++) fwrite($fp, chr($annee[$i]));
fclose($fp);
?>


mais comment envoyer un array javascript vers mon php
0
Rejoignez-nous