Custom field type file upload error [Uploaded File Class]
Yii’s CUploadedFile class actually doesn’t support retrieving uploaded files that came from a file input whose name was “namespaced” (e.g. name="fields[handle]" rather than just name="handle").

However, Craft has its own UploadedFile class which extends CUploadedFile, and the whole point of it is to add that namespaced input name support. It uses a dot syntax rather than square brackets, so if a file input had the name fields[handle], you would fetch that file like this:



$file = UploadedFile::getInstanceByName('fields.handle');


Problem is, you can’t actually rely on the file input name having a fields namespace – it will vary depending on the form. In fact many element forms within Craft have randomized namespaces (e.g. the Quick Post dashboard widget, or the modal windows that come up when you double-click on an element within a relational field).

That’s why field types have a getContentPostLocation() method, which returns the input name that would have been used for the current field, namespace and all, converted into dot syntax. So you can plug that value directly into getInstanceByName() and get your uploaded file.

$contentPostLocation = $this-&gt;getContentPostLocation();

if ($contentPostLocation)
{
    $file = UploadedFile::getInstanceByName($contentPostLocation);

    // ...
}