PDA

View Full Version : upload security check



rille31
November 25th, 2006, 01:19 PM
Im using te fileReference class to upload documents, the problem I have is that flash doesnt send the mime type and I want to validate that the mime type is correct for security reasons.

Anybody knows a fix to this?

The code works in a regular html form but not with the fileReference class

<?php
if (!empty($_FILES['Filedata']['name'])){
$fil = $_FILES['Filedata']['name'];
if (preg_match("/\.(?:txt|doc|pdf)$/i", $fil)){
$mime = $_FILES['Filedata']['type'];
if($mime == "application/msword" || $mime == "text/plain" || $mime == "application/pdf") {
$timeStamp = time();
$uploadDir = "files/";
$uploadFile = $uploadDir ."$timeStamp-". $_FILES['Filedata']['name'];
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
}
}
}
?>

bwh2
November 25th, 2006, 01:25 PM
you really didn't need to create a 2nd thread for this.

this probably doesn't work because $_FILES isn't being populated.

bigmtnskier
November 25th, 2006, 01:39 PM
<pet type="peeve">
Why did you put $timeStamp inside the quotes?
"$timeStamp-"</pet>

rille31
November 26th, 2006, 09:12 AM
<pet type="peeve">
Why did you put $timeStamp inside the quotes?
"$timeStamp-"</pet>
I added a string to the end of the variabel and was to lazy.
I guess I could or propably should put it without quotes but It works in both ways in php right?