Search code examples
phpuploadifylithium

Disable render process in lithium


i use uploadify for my upload process. The problem is that after each upload lithium tries to render the view of the controller. In my case uploadify.html.php. How can i disable this behaviour and just return a 200 OK.

My controller code:

class UploadController extends \app\controllers\AppController {

public function index() {}

public function uploadify() {
    Logger::write('info', 'start upload');

    if (!empty($this->request->data)) {
        $fileData = $this->request->data['Filedata'];
        $error = $fileData['error'];
        if($error == UPLOAD_ERR_OK) {
            // everything ok
            $tempFile = $fileData['tmp_name'];
            $targetPath = $this->request->env('DOCUMENT_ROOT') . $fileData['folder'] . '/';
            $targetFile =  str_replace('//','/',$targetPath) . $fileData['name'];
            move_uploaded_file($tempFile, $targetFile);
            Logger::write('info', 'upload file successfull to ' . $targetFile);
        } else if($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE) {
            // file size to large
            Logger::write('error', 'file to large ' . $fileData['Filename']);
        } else if($error == UPLOAD_ERR_PARTIAL) {
            // only partial uplopad
            Logger::write('error', 'uploaded partial ' . $fileData['Filename']);
        } else if($error == UPLOAD_ERR_NO_FILE) {
            // no file uploaded
            Logger::write('error', 'couldn\'t upload ' . $fileData['Filename']);
        } else {
            Logger::write('error', 'Unknown error code ' . $error);
        }
    } else {
        Logger::write('error', 'no form data');
    }
}
}

Solution

  • To only renders the headers of the response, not the body, set

    $this->render(array('head' => true))
    

    Same with redirect()

    Docs: http://li3.me/docs/lithium/action/Controller::render