Version: current

     1 <?php
     2 // вася
     3 class MultiUploadControls extends Controller {
     4     public static $image_class = "Image";
     5     public static $file_class = "File";
     6
     7     public function handleupload() {
     8         if (isset($_FILES["upload_file"]) && is_uploaded_file($_FILES["upload_file"]["tmp_name"])) {
     9             $ext = strtolower(end(explode('.', $_FILES['upload_file']['name'])));
    10             $class = in_array($ext, array('jpg','jpeg','gif','png')) ? self::$image_class : self::$file_class;
    11             $file = new $class();
    12             $u = new Upload();
    13             $dir = MultiUploadConfig::get_var('default_upload_dir');
    14             if(!$dir) $dir = "Uploads";
    15             $u->loadIntoFile($_FILES['upload_file'], $file, $dir);
    16             $file->write();
    17             echo $file->ID;
    18         }
    19         else {
    20             echo ' '; // return something or SWFUpload won't fire uploadSuccess
    21         }
    22
    23     }
    24 }

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -