1. About.com
  2. Computing & Technology
  3. PHP / MySQL

Discuss in my forum

Uploading Files with PHP

By , About.com Guide

Limit Files by Type
 if ($uploaded_type =="text/php")
 {
 echo "No PHP files<br>";
 $ok=0;
 } 
The code above checks to be sure the user is not uploading a PHP file to your site. If they do upload a PHP file, they are given an error, and $ok is set to 0.
 if (!($uploaded_type=="image/gif")) {
 echo "You may only upload GIF files.<br>";
 $ok=0;
 } 
In our second example we only allow users to upload .gif files, and all other types are given an error before setting $ok to 0. You can use these basic examples to allow or deny any specific file types.

©2012 About.com. All rights reserved. 

A part of The New York Times Company.