Jump to content

Uploading only one file type


LanceT

Recommended Posts

you need to check the MIME type or $_FILES['type'] variable, create an array to hold the allowed types and then you can compare the upload against the array. there are additional checks you can perform, but this is the most basic.

 

Here is a basic tutorial i found:

http://php.about.com/od/advancedphp/ss/php_file_upload_2.htm

 

Here is a link for MIME types:

http://www.ltsw.se/knbase/internet/mime.htp

somethink like this ok.

 

<?php 
$target = "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 

$_FILES['type']=array(".jpg",".png",".gif");

foreach($_FILES['type'] as $wanted_file_type){

if(!$wanted_file_type){

echo "sorry you must only use the following file type <br> .jpg <br>
.png <br> .gif <br> please try agin";
}
}
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.