Learning PHP and MySQL

Saturday, August 19, 2006

Example 11-27 Checking the file type

Example 11-27 checks the file type to make sure it’s either a JPEG or a GIF file.

<?php

if($HTTP_POST_FILES['upload_file']['type']  !=  "image/gif"  AND
$HTTP_POST_FILES['upload_file']['type']  !=  "image/pjpeg"  AND
$HTTP_POST_FILES['upload_file']['type']  !="image/jpeg")  {
   $error  
=  "You  may  only  upload  .gif  or  .jpeg  files";
   
unlink($HTTP_POST_FILES['upload_file']['tmp_name']);
}  else  {
   
//the  file  is  the  correct  format
}

?>

The following line copies the file from the temporary directory into the uploads direc- tory using the same filename.

copy($HTTP_POST_FILES['upload_file']['tmp_name'],"uploads/".
$HTTP_POST_FILES['upload_file']['name']);

Using unlink, let’s remove the temporary file.

unlink($HTTP_POST_FILES['upload_file']['tmp_name']);

Posted by krautgrrl on 08/19 at 08:46 AM
Chapter 11 Code • (1) Comments • (0) TrackbacksPermalink

Statistics

This page has been viewed 407318 times
Page rendered in 0.2315 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 10
Total anonymous users: 0
Most Recent Visitor on: 05/19/2012 06:02 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine