473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Restrict file types in upload

FullyH3ktik
Hey does anybody know how to restrict the file type .exe from uploading?

thanks in advance
Oct 1 '07 #1
3 2591
djpaul
137 100+
You could use the function eregi.

Like so:
[PHP]
[PHP]if (eregi (.exe*)){
//.exe file exists
}else{
//.exe. doesn't exist
}
[/PHP]

Gr Paul
Oct 1 '07 #2
Could you perhaps write a "mini script" to show me how you would incorporate that into the file upload
Much appreciated.
Oct 2 '07 #3
maqeel
1
Here is a snippet to restrict file type uploads:

Expand|Select|Wrap|Line Numbers
  1. $allowedExtensions = array("txt","csv","htm","html","xml","css","doc","xls","rtf","ppt","pdf","swf","flv","avi","wmv","mov","jpg","jpeg","gif","png");
  2.     foreach ($_FILES as $file) {
  3.         if ($file['tmp_name'] > '') {
  4.             if (!in_array(end(explode(".",strtolower($file['name']))),$allowedExtensions)) {
  5.                 die($file['name'].' is an invalid file type!<br/>'.'<a href="javascript:history.go(-1);">'.'&lt;&lt Go Back</a>');
  6.             }
  7.         }
  8.     }
Feb 4 '12 #4

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

Similar topics

2
by: dhnriverside | last post by:
Hi I'm trying to restrict file types with a HtmlInputFile Accept property. It seems that this isn't supported for IE6? (doh!). Can anyone recommend any free Upload components? Or a solution? ...
5
by: Jon Natwick | last post by:
I would like to limit the file types that users can upload. <input id="tbFileUpload" type="file" runat="server"> This setting looks like it should it work, but it's not working for me. ...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
5
by: Seok Bee | last post by:
Dear Experts, I currently trying to use the FileUpload control from asp.net 2.0 to upload files. The uploading of the file I would like to store it in the Access Database. Unfortunately, I've no...
21
by: Niu Xiao | last post by:
I see a lot of use in function declarations, such as size_t fread(void* restrict ptr, size_t size, size_t nobj, FILE* restrict fp); but what does the keyword 'restrict' mean? there is no...
0
by: Webmills | last post by:
Hi I have a form containing a File Upload Control, Required Field Validator (connected to the file upload control) RegularExpressionValidator (connected to the file upload control,...
1
by: gryffin | last post by:
im trying to do file extension checking but its not working :( i have the following in the head <script language="JavaScript"> extArray = new Array(".jpg", ".png", ".bmp"); function...
1
by: fortwilliam | last post by:
Hi, I am very new to "object oriented programming". I have this script which I didn't write but have altered and have been using for a while to allow people to upload files to a website. Now I am...
7
Curtis Rutland
by: Curtis Rutland | last post by:
Building A Silverlight (2.0) Multi-File Uploader All source code is C#. VB.NET source is coming soon. Note: This project requires Visual Studio 2008 SP1 or Visual Web Developer 2008 SP1 and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.