اندازه فایل قبل از ارسال

سلام
آیا راهی هست که اندازه فایل رو قبل از آپلود فهمید مثلا کاری کرد که اگه اندازه 100*100 پیکسل نباشه فایل رو اپلود نکنه
 

zoghal

Active Member
توضیح نداره دوست من کافیه تو گوگل سرچ کنید انواع روش ها رو پیدا میکنید. این هم دو نمونه
PHP:
<html>
<head>
<script language="JavaScript">
function A()
{
var oas = new ActiveXObject("Scripting.FileSystemObject");
var d = document.a.b.value;
var e = oas.getFile(d);
var f = e.size;
alert(f + " bytes");
}
</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>

PHP:
<script language="javascript">
		//BEGIN FROM http://weblogs.macromedia.com/cantrell/archives/2004/06/how_to_implemen.cfm
		var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;
		function previewImage(pathField, previewName)
		{ 
		var path = pathField.value;
		if (path.search(imgRe) != -1)
		{ 
		document[previewName].src = 'file://'+path;
		//END FROM http://weblogs.macromedia.com/cantrell/archives/2004/06/how_to_implemen.cfm
		
		{
		var img = new Image();
		img.src = 'file://'+path;
		document.write(img.width + ' pixels wide x ' + img.height +' pixels  		high<br>'+ '<img src=' + img.src + '><br>');
		
		}
		
		{
		// BEGIN FROM: http://www.quirksmode.org/js/filesize.html
		var size = (document.fileSize)*1;
		var y = document.images;
		var imglength = 0;
		for (i=0;i<y.length;i++)
		{
		imglength += (y[i].fileSize)*1;
		}
			var total = size + imglength;
		//uncomment the following to return more page info
		//var writestring = 'File size HTML: ' + size;
		//writestring += '\nFile size images: ' + imglength;
		//writestring += '\nTotal file size: ' + total;
		// END FROM: http://www.quirksmode.org/js/filesize.html
		var writestring = 'Image file size: ' + imglength + ' bytes<br>' ;
		if (imglength < 1) writestring += "<b>NOT APPLICABLE: \nFile too large  		for this script.</B><BR>";
		
		//if (total > 40000) writestring += "\nFile too large!" + '<a href="javascript:  		history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>';
		
		if (imglength > 40000) writestring += "\nFile too large!" + '<a href="javascript:  		history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>';
		
		//if (total < 40000) writestring += "\nFile size OK." + '<a href="javascript:  		history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>';
		
		//if (imglength >= 1)writestring += "\nFile size OK." + '<a href="javascript:  		history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>';
		
		if (((40000 + imglength)<40000)) writestring +="\nFile size not OK." +  		'<a href="javascript: history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>' ;
		
		if (((40000 + imglength)>40000)) writestring +="\nFile size OK." + '<a  		href="javascript: history.go(-1)"><br>RETURN TO PREVIOUS PAGE</a>' ;
		document.write(writestring);
		
		}
		
		} 
		else 
		{ 
		alert("JPG, PNG, and GIFs only!");
		} 
		}
		</script>
 

جدیدترین ارسال ها

بالا