Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

issue with setMIMETypes in fUpload

posted by oliverd 9 years ago

I've come across an odd issue with the fUpload class. I've created a form to upload a file, and I want to restrict the file type to CSV.


$uploader = new fUpload();
$uploader->setMIMETypes(array('text/csv'), 'The file uploaded in not in CSV format.');
		
try
{
	$file = $uploader->move(UPLOAD_PATH, 'dataFile');
}
catch (fValidationException $e)
{
	fMessaging::create('error', fURL::get(), $e->getMessage());	
}

Every time I upload a CSV file, I get my error message. However, when I remove the restriction, it works fine. Then when I do the following:

echo $file->getMimeType();

It outputs "text/csv". Any idea what I am doing wrong, or is this a possible bug?

When Flourish checks the mime type, first it tries to look at the file contents. If the file contents are non conclusive, then it uses the filename extension. In this case the temporary file used during uploading does not have the .csv file extension that is does after it is moved. Thus the two different mime types are reported at different times.

I'll have to update fFile to take into account the final filename rather than the temporary one.

posted by wbond 9 years ago

This should be fixed in r833.

posted by wbond 9 years ago