1. Home
  2. Computing & Technology
  3. PHP / MySQL

Uploading Files with PHP

By , About.com Guide

4 of 6

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.
Explore PHP / MySQL
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. Advanced PHP
  5. PHP File Upload - PHP Upload Script - Upload file script

©2009 About.com, a part of The New York Times Company.

All rights reserved.