1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
window.onload = function(){formPhoto(1)};
function formPhoto(id)
{
var table = document.createElement('table');
table.id = 'tableUp'+id;
table.setAttribute('border','0');
table.setAttribute('cellpadding','0');
table.setAttribute('cellspacing','0');
var tr = document.createElement('tr');
var td = document.createElement('td');
td.id = 'formUp'+id;
var td2 = document.createElement('td');
td2.id = 'fileUp'+id;
var form = document.createElement('form');
form.setAttribute('action','php/annonce/uploadPhoto.php');
form.setAttribute('method','post');
form.setAttribute('enctype','multipart/form-data');
form.setAttribute('target','uploadTarget');
form.setAttribute('name','form'+id);
var input = document.createElement('input');
input.setAttribute("type","file");
input.setAttribute("name", "photo"+id);
input.setAttribute("onChange", "uploadPhoto("+id+")");
var hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.value = id;
hiddenInput.setAttribute("name","hiddenField");
td.appendChild(hiddenInput);
td.appendChild(input);
tr.appendChild(td);
tr.appendChild(td2);
table.appendChild(tr);
form.appendChild(table);
document.getElementById('formPhoto').appendChild(form);
}
function uploadPhoto(id)
{
document.getElementById("fileUp"+id).innerHTML = "<img src=img/chargeur.gif />Chargement en cours";
document.forms["form"+id].submit();
}
function uploaded(nPhoto, id)
{
document.getElementById("fileUp"+id).innerHTML = "<a href=# onclick=previewPhoto('"+nPhoto+"')>"+nPhoto+"</a>";
document.getElementById("previewPhoto").innerHTML = "<img src=http://localhost/okaz/temp/"+nPhoto+" alt="+nPhoto+" />";
id++;
formPhoto(id);
}
function previewPhoto(nPhoto)
{
document.getElementById("previewPhoto").innerHTML = "<img src=http://localhost/okaz/temp/"+nPhoto+" alt="+nPhoto+" />";
}
function errorUpload(id, erreur)
{
var error = new Array ;
error[0] = 'Extension du fichier incorrecte';
error[1] = 'Le fichier est trop gros';
error[2] = 'Erreur lors du transfert de fichier';
document.getElementById("fileUp"+id).innerHTML = error[erreur];
} |