Example #1
0
    /**
     * Gets called by the SWFUpload Object for uploading files
     * @return
     */
    function FileUpload()
    {
        $db =& $this->db;
        Debug::LogEntry('audit', 'Uploading a file', 'Library', 'FileUpload');
        Kit::ClassLoader('file');
        $fileObject = new File($db);
        // Check we got a valid file
        if (isset($_FILES['media_file']) && is_uploaded_file($_FILES['media_file']['tmp_name']) && $_FILES['media_file']['error'] == 0) {
            Debug::LogEntry('audit', 'Valid Upload', 'Library', 'FileUpload');
            // Directory location
            $libraryFolder = Config::GetSetting('LIBRARY_LOCATION');
            $error = 0;
            $fileName = Kit::ValidateParam($_FILES['media_file']['name'], _FILENAME);
            $fileId = $fileObject->GenerateFileId($this->user->userid);
            $fileLocation = $libraryFolder . 'temp/' . $fileId;
            // Make sure the library exists
            File::EnsureLibraryExists();
            // Save the FILE
            Debug::LogEntry('audit', 'Saving the file to: ' . $fileLocation, 'FileUpload');
            move_uploaded_file($_FILES['media_file']['tmp_name'], $fileLocation);
            Debug::LogEntry('audit', 'Upload Success', 'FileUpload');
        } else {
            $error = isset($_FILES['media_file']) ? $_FILES['media_file']['error'] : -1;
            $fileName = 'Error';
            $fileId = 0;
            Debug::LogEntry('audit', 'Error uploading the file. Error Number: ' . $error, 'FileUpload');
        }
        $complete_page = <<<HTML
        <html>
            <head>
                <script type="text/javascript">

                    var fileId = '{$fileId}';
                    var fileName = '{$fileName}';
                    var errorNo = {$error};

                    function report()
                    {
                        var form = window.parent.fileUploadReport(fileName, fileId, errorNo);
                    }

                    window.onload = report;

                </script>
            </head>
            <body></body>
        </html>
HTML;
        echo $complete_page;
        Debug::LogEntry("audit", $complete_page, "FileUpload");
        Debug::LogEntry("audit", "[OUT]", "FileUpload");
        exit;
    }