PDA

View Full Version : UPLOADING Page but no MIME for file



chopper
04-24-2008, 10:13 PM
Hi

I have code to upload files to server using php. The problem is (well so I think) that the file type I'm wanting to upload, *.aiml, does not have a mime type?!?!

Any ideas how I can adjust / re-work code to only allow files with the extension aiml.

Thanks


<?php
if(isset($_POST['submit'])){
$numfilesuploaded = $_POST['numuploads'];
$count = 1;

while ($count <= $numfilesuploaded)
{
$conname = "new_file".$count;

$filetype = $_FILES[$conname]['type'];

$filename = $_FILES[$conname]['name'];
if ($filename != '')
{
if ($filetype == "application/msword")
{
$maxfilesize = $_POST['maxsize'];
$filesize = $_FILES[$conname]['size'];
if($filesize <= $maxfilesize )
{
$randomdigit = rand(0000,9999);

$newfilename = $randomdigit.$filename;
$source = $_FILES[$conname]['tmp_name'];
$target = "files/".$newfilename;
move_uploaded_file($source, $target);
echo $count." File uploaded | ";


}
else
{
echo $count." File is too big! 10MB limit! |";

}
}
else
{
echo " The file is not a supported type |";
}
}
$count = $count + 1;
}

}
?>
<html>
<?php
$numuploads = 5;
$count = 1;
?>
<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<?php
while ($count <= $numuploads)
{

?>
<input name="new_file<?php echo $count; ?>" id="new_file<?php echo $count; ?>" size="30" type="file" class="fileUpload" />
<?php
$count = $count + 1;
}
?>
<input type = "hidden" name="maxsize" value = "10240000">
<input type = "hidden" name="numuploads" value = "<?php echo $numuploads; ?>">
<br>
<button name="submit" type="submit" class="submitButton">Upload Files</button>

</form>
</html>

I got the code from:

http://www.theopensurgery.com (http://www.theopensurgery.com/05/useful-multiple-file-upload-php-script/#comment-290)