文件大小 [英] File Size

查看:68
本文介绍了文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JavaScript可以检测图像文件的大小吗?


Ken

Can JavaScript detect the size of an image file?

Ken

推荐答案

2004年9月6日星期一15:39:18 -0500,Ken写道:
On Mon, 6 Sep 2004 15:39:18 -0500, Ken wrote:
JavaScript可以检测图像文件的大小吗?
Can JavaScript detect the size of an image file?




我不知道是否有其他方法可以做到,但

...您的服务器是否会返回这样的文件列表?

< http://www.physci.org/test/screenshot/>


这是我服务器上的一个目录,包含

没有''索引' '页面,所以服务器写一个文件列表

...完整的文件大小。


假设你可以使用JS访问元素,
您可以在隐藏的

或IFRAME中加载该页面并解析它以获取信息。


但请注意,我只是潜伏在这里

试图从专家那里获取技巧。 ;-)


-

Andrew Thompson
http://www.PhySci.org/ 开源软件套件
http://www.PhySci.org/codes/ Web& IT帮助
http://www.1point1C.org/ Science&技术



I do not know if there are other ways to do it, but
...does your server return file listings like this?
<http://www.physci.org/test/screenshot/>

That is a directory on my server that contains
no ''index'' page, so the server writes a file list
...complete with file size.

Assuming you can access the elements using JS,
you might be able to load that page in a hidden
or IFRAME and parse it for the information.

Be warned though, that I am merely lurking here
trying to pick up tips from the experts. ;-)

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology


Ken写道:
Ken wrote:
JavaScript可以检测图像文件的大小吗?

Ken
Can JavaScript detect the size of an image file?

Ken




不,JavaScript不行。但是,至少有一个用户代理有一个

主机Image对象,其中包含一个属性,可让您访问所需的信息

。然后可以使用JavaScript来
访问该主机对象属性:


< url:
http://msdn.microsoft.com/workshop/a...s/filesize。 asp

/>


< body onload =" alert(document.images [''myImage'']。fileSize) ;">

< img name =" myImage" src =" myImage.gif">

< / body>


请注意IE 6SP1,Firefox 0.9.3,Mozilla 1.7.2 ,Opera 7.54,

Opera 6.05和Netscape 4.78,只有IE在上面的代码示例中没有报告undefined




另一种可能性是在IE和基于Gecko的浏览器中使用XML HTTP Request对象

来对图像进行HEAD请求

。返回的标题应包含图像

size(Content-Length)< url:
http://jibbering.com/2002/4/httprequest.html /> ;.


最后,如果您有任何类型的服务器端技术(ASP,JSP,Perl,PHP等),您可以使用它来检索

的大小图像然后通过该价值为

客户端javascript


<?php

#use PHP确定图像的大小

?>

< script type =" text / javascript">

var imageSize =<?php echo



No, JavaScript can not. However, at least one user agent has a
host Image object which includes a property that lets you access
the information you require. JavaScript can then be used to
access that host object property:

<url:
http://msdn.microsoft.com/workshop/a...s/filesize.asp
/>

<body onload="alert(document.images[''myImage''].fileSize);">
<img name="myImage" src="myImage.gif">
</body>

Note that of IE 6SP1, Firefox 0.9.3, Mozilla 1.7.2, Opera 7.54,
Opera 6.05 and Netscape 4.78, only IE does not report "undefined"
in the above code example.

The other possibility would be to use the XML HTTP Request object
available in IE and Gecko-based browsers to do a HEAD request for
the image. The headers that get returned should contain the image
size (Content-Length) <url:
http://jibbering.com/2002/4/httprequest.html />.

Lastly, if you have any sort of server-side technology available
to you (ASP, JSP, Perl, PHP, etc), you could use it to retrieve
the size of the image and then "pass" that value to the
client-side javascript:

<?php
# use PHP to determine the size of the image
?>
<script type="text/javascript">
var imageSize = <?php echo


imageSize?> ;;

< / script>


-

Grant Wagner< gw ***** @ agricoreunited.com>

comp.lang.javascript常见问题 - http://jibbering.com/faq

imageSize ?>;
</script>

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq


这篇关于文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆