473,835 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

restriction for uploading images in asp

47 New Member

i have an option for the users to upload their image...
but i want to allow only gif and jpg file extension....

how to check whether the uploaded image is gif or jpg,,
and display error message when invalid file uploaded..

with regards
Aug 7 '06 #1
3 2165
34 New Member
you can validate using javascript before uploading the file if the it has .gif or .jpg as the extension and then according generate error message

just let me know if its works
Aug 13 '06 #2
1,754 Recognized Expert Top Contributor
Hi Meenu,

kindly refer to below sample code segment.. good luck and take care my fren.. :)


1. Copy the coding into the HEAD of your HTML document
2. Add the last code into the BODY of your HTML document -->

<!-- STEP ONE: Paste this code into the HEAD of your HTML document -->

Expand|Select|Wrap|Line Numbers
  1. <HEAD>
  2. <script type="text/javascript">
  3. <!-- Begin
  6.   // width to resize large images to
  7. var maxWidth=100;
  8.   // height to resize large images to
  9. var maxHeight=100;
  10.   // valid file types
  11. var fileTypes=["bmp","gif","png","jpg","jpeg"];
  12.   // the id of the preview image tag
  13. var outImage="previewField";
  14.   // what to display when the image is not valid
  15. var defaultPic="spacer.gif";
  17. /***** DO NOT EDIT BELOW *****/
  19. function preview(what){
  20.   var source=what.value;
  21.   var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  22.   for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  23.   globalPic=new Image();
  24.   if (i<fileTypes.length) globalPic.src=source;
  25.   else {
  26.     globalPic.src=defaultPic;
  27.     alert("THAT IS NOT A VALID IMAGE\nPlease load an image with an extention of one of the following:\n\n"+fileTypes.join(", "));
  28.   }
  29.   setTimeout("applyChanges()",200);
  30. }
  31. var globalPic;
  32. function applyChanges(){
  33.   var field=document.getElementById(outImage);
  34.   var x=parseInt(globalPic.width);
  35.   var y=parseInt(globalPic.height);
  36.   if (x>maxWidth) {
  37.     y*=maxWidth/x;
  38.     x=maxWidth;
  39.   }
  40.   if (y>maxHeight) {
  41.     x*=maxHeight/y;
  42.     y=maxHeight;
  43.   }
  44.   field.style.display=(x<1 || y<1)?"none":"";
  45.   field.src=globalPic.src;
  46.   field.width=x;
  47.   field.height=y;
  48. }
  49. // End -->
  50. </script>
  51. </HEAD>
<!-- STEP TWO: Copy this code into the BODY of your HTML document -->

Expand|Select|Wrap|Line Numbers
  1. <BODY>
  2. <div align="center" style="line-height: 1.9em;">
  3. Test it by locating a valid file on your hard drive:
  4. <br>
  5. <input type="file" id="picField" onchange="preview(this)">
  6. <br>
  7. <img alt="Graphic will preview here" id="previewField" src="spacer.gif">
  8. <br> <div style="font-size: 7pt;">
  9. Script submitted by: <a href="http://www.abrahamjoffe.com.au/">Sydney Wedding Video / DVD</a></div>
  10. </div>
  12. <p><center>
  13. <font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
  14. by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
  15. </center><p>
  16. </BODY>
Aug 15 '06 #3
4 New Member

How upload and display image in asp .Pls can u suggest sir,Once we upload the image file it is inserts into database and display image it can could show where we insert....

Kindly Regards,
Oct 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: lion | last post by:
I get these errors when uploading images via a web page: (the page still uploads the images but reports these errors?) Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) : failed to create stream: No error in D:\webspace\me.co.uk\wwwroot\test\Live.php on line 105 Warning: Wrong parameter count for filesize() in D:\webspace\me.co.uk\wwwroot\test\Live.php on line 109
by: laredotornado | last post by:
Hi, I'm using PHP 4 and I am submitting some images in a form with <form name=addProductForm enctype="multipart/form-data" method=post action="add_product_response.php"> <input type=file name='prodImg' id='prodImg'> However, sometimes, the images fail to upload, even though the form submits fine. When I try to print out the values from the $_FILES array, I get
by: Roger Withnell | last post by:
I would like to check that an image file, selected by a user using fileUpload, is within certain parameters (width, height, filesize) and to display the image file so that the user can see the correct image has been chosen, before uploading it to the server. http://www.your-community.co.uk/TestImageArray.asp is an extract of the basic functions which work in IE but not in NN (the alerts are just tests to see what is going on). It...
by: psb | last post by:
WHO HAS THE BEST COMPONENT FOR FILE UPLOAD? HELP!? has anyone achieved 100% success with HTTP uploading with Mac clients??? I thought the whole <input type="file" .../> was a w3c standard that goes back 10 years!! I have been doing web development with either asp or asp.net since 1998. I have implemented almost every methodology for file uploading -> com+, asp w/ado.stream, asp.net, asp.net private assemblies. In my past...
by: Gavin | last post by:
I need some help, I need the code to allow people that visit my website to be able to upload pictures to a file on my web server. I have been able to get close, but not quite there yet. Set fso = createobject("scripting.filesystemobject") Set act = fso.CreateTextFile(server.mappath("test.jpg"), true) act.WriteLine act.Close The above code will create the file but will not write any data in it. Below
by: joe | last post by:
Any articles relating with Uploading images files to server and resize the image by asp.net 2.0
by: Deejam | last post by:
hi, i've this situations where user will upload images..my code works fine for uploading images.. but i need to create auto thumbnail picture (of the same image) whenever user upload images... help me how to create thumbnail picture.. is my question clear? thk in advance
by: thulaseeram | last post by:
I am using iframe to store uploaded images, it is uploading fine in IE but it is not happening in firefox means first time it is uploading image if i try to upload second image it is not calling even java script function and not uploading the image in firefox. I am using this code in the button onclick event "attach_frame.upload();" here attach_frame is the iframe name and id to which the uploaded image should add. please can any one help me to...
by: w33nie | last post by:
What I'm trying to do here, is upload a video to the ../video/ folder, and up to 5 images to the ../images/ folder. As well as the database information like title, content and each file's file information. But I really have no idea how to do this. The whole move_uploaded_file part is obviously wrong, but I'm not sure where to go from here to achieve my ends. $videoUploadDir = '../video/'; $imageUploadDir = '../images/'; ...
by: pezholio | last post by:
Hi, It seems that every time I put together a new script to upload a file I always have problems, here's the latest one: I've got a form with two file input fields, when I submit the form, everything goes OK, but the files don't upload, the permissions on the folders are fine and dandy (Both 777). Here's my code: if(is_uploaded_file($_FILES)){ $target_path = "/home/default/ratemyplace.org.uk/user/htdocs/newsite/images/premimages/";
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.