Ciao a tutti.
Sto utilizzando lo script che riporto qui sotto... vorrei disabilitare il campo di input una volta che l'utente ha inserito un numero di immagini prestabilito.
Purtroppo non sono molto ferrato in js. Mi dareste una mano? Grazie.
Codice PHP:
<?php
if(isset($_FILES['fImage']['tmp_name']))
$ftmp = $_FILES['fImage']['tmp_name'];
if(isset($_FILES['fImage']['name'])) {
$oname = $_FILES['fImage']['name'];
$fname = 'upload/'.$_FILES['fImage']['name'];
}
if(@move_uploaded_file($ftmp, $fname)){
?>
<script>
var par = window.parent.document;
var images = par.getElementById('images');
var imgdiv = images.getElementsByTagName('div')[<?=(int)$_POST['imgnum']?>];
var image = imgdiv.getElementsByTagName('img')[0];
imgdiv.removeChild(image);
var image_new = par.createElement('img');
image_new.src = 'resize.php?pic=<?=$oname?>';
image_new.className = 'loaded';
imgdiv.appendChild(image_new);
</script>
<?php
exit();
}
?>
<script language="javascript">
function upload(){
// hide old iframe
var par = window.parent.document;
var num = par.getElementsByTagName('iframe').length - 1;
var iframe = par.getElementsByTagName('iframe')[num];
iframe.className = 'hidden';
// create new iframe
var new_iframe = par.createElement('iframe');
new_iframe.src = 'upload.php';
new_iframe.frameBorder = '0';
new_iframe.marginHeight = '0';
new_iframe.marginWidth = '0';
par.getElementById('iframe').appendChild(new_iframe);
// add image progress
var images = par.getElementById('images');
var new_div = par.createElement('div');
var new_img = par.createElement('img');
new_img.src = 'indicator.gif';
new_img.className = 'load';
new_div.appendChild(new_img);
images.appendChild(new_div);
// send
var imgnum = images.getElementsByTagName('div').length - 1;
document.iform.imgnum.value = imgnum;
[COLOR=red]if(imgnum > 0) {
document.iform.fImage.disabled = true;
alert('Puoi inserire un massimo di 5 fotografie');
}
[/COLOR]
setTimeout(document.iform.submit(), 5000);
}
</script>
<form name="iform" action="<?= $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
<input id="file" type="file" name="fImage" onChange="upload()" size="68" class="file-input" />
<input type="hidden" name="imgnum" />
</form>