I often see a friend asking me how to obtain the size of the uploaded file on the client. This problem also plagued me and took a long time to upload the file to the server, after judging, we can know that the size of the file uploaded by the customer exceeds the size set by us. At this time, we will return this information to the customer, which is not very good.
A friend posted a piece in the forum a few days ago to get the size of the uploaded image. I saw it and tried it. It felt really good and I thought I could not get the size of the file, I was disappointed that I didn't see this method when I checked MSDN.
I just saw-erquan said that the DHTML document can be downloaded in PHP, so I can't wait to find it. I'm not disappointed. In the DHTML document, I see this attribute filesize, you can obtain the size of an image displayed in the browser.
We can use it to view the image size.
------------
Code
------------
<HTML>
<HEAD>
<Meta name = "GENERATOR" Content = "Microsoft Visual Studio 6.0">
<TITLE> </TITLE>
</HEAD>
<Script language = javascript>
<! --
Function changephoto ()
{
Document. all. img1.src = document. all. file1.value;
}
Function show ()
{
If (document. all. file1.value = "")
Alert ("image not selected ");
Else
Alert ("selected image size:" + document. all. img1.fileSize + "width:" + document. all. img1.width + "height:" + document. all. img1.height );
}
// -->
</SCRIPT>
<BODY>
<FORM action = "" method = POST id = form1 name = form1>
<P> <INPUT id = file1 type = file name = file1 onchange = "changephoto ()"> </P>
</FORM>
<A href = "Javascript: show ()"> test </a>
<Br>
</BODY>
</HTML>
This code can be used to obtain the size of the image to be uploaded. However, it seems a bit incompetent for uploading other types of files, and there is another problem, no matter which method you want to hide IMG1, you can get the size of the image, but you cannot get the size of the image.
I want to discuss it with you. On the client side, apart from writing OCX, there is no simpler way to get the size of the file to be uploaded.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.