I have a plugin Controller that accepts a POSTed form, including an uploaded file. If I make an Assets Source I can successfully save the file into its folder like this:
$file = UploadedFile::getInstanceByName('myFieldName');
$folder = craft()->assets->findFolder(array(
'sourceId' => 3, // My Asset Source's ID.
));
$response = craft()->assets->insertFileByLocalPath(
$file->getTempName(), // Local path to file.
$file->getName(), // Name file should be given when saved.
$folder->id,
AssetConflictResolution::KeepBoth
);
if ($response->isSuccess()) {
...
However, I want to upload the file to a folder that's not an Asset Source - for security reasons I don't want these particular files to be visible in any way in the CMS. Is there a way to do this, eg, by using a filepath rather than an Asset Source?
(I'm also not sure how to validate the file, in terms of its file extension, size, etc. I can see how to do this in Yii but I'm not sure how to do it having uploaded the file as above.)