<input id="button2" type="file">
new AjaxUpload('#button2', {
action: 'upload.php',
onSubmit : function(file , ext){
if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
// extension is not allowed
alert('Error: invalid file extension');
// cancel upload
return false;
}
}
});
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "success";
} else {
// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
// Otherwise onSubmit event will not be fired
echo "error";
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="./prototype.js"></script> <script type="text/javascript" src="./ajaxupload.js"></script> <script> new AjaxUpload('#button2', { action: './upload.php', onChange : function(file , ext){ if (! (ext && /^(jpg|png|jpeg|gif|txt)$/.test(ext))){ // extension is not allowed alert('Error: invalid file extension'); // cancel upload return false; } } }); </script> </head> <body> <form action="#" method="get"> <input id="button2" type="file"> </form> </body> </html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script type="text/javascript" src="./prototype.js"></script> <script type="text/javascript" src="./ajaxupload.js"></script> <script> var count_annex = 0; var champ_annex = ""; var annex_suivant = 0; function add_annex(id){ annex_suivant = count_annex + 1; var tbody = $(id).getElementsByTagName("TBODY")[0]; var row = document.createElement("TR"); var td1 = document.createElement("TD"); td1.appendChild(document.createTextNode("column "+annex_suivant)); var td2 = document.createElement("TD"); td2.innerHTML = '<input type="button" value = "Parcourir" id="annexadded'+count_annex+'"/>'; row.appendChild(td1); row.appendChild(td2); tbody.appendChild(row); eval(new AjaxUpload('#annexadded'+count_annex, { action: './upload.php', onChange : function(file , ext){ if (! (ext && /^(jpg|png|jpeg|gif|txt)$/.test(ext))){ // extension is not allowed alert('Error: invalid file extension'); // cancel upload return false; } } }) ); champ_annex = ""; count_annex++; } </script> </head> <body> <table id="myTable" cellspacing="0" border="1"> <tbody> </tbody> </table> <a href="javascript:add_annex('myTable')">Add row</a> </body> </html>
Combien cela coûte-t-il au total ? Quelles aides apportent l'état et les acteurs du marché pour alléger cette charge non choisie ? Tous les détails sur Commentçamarche.net.