<commit_before><?php
class Kwf_Controller_Action_Media_UploadController extends Kwf_Controller_Action
{
    public function jsonUploadAction()
    {
        $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')
            ->createRow();

        if (isset($_FILES['Filedata'])) {
            $file = $_FILES['Filedata'];
            if ($file['error']) {
                if ($file['error'] == UPLOAD_ERR_NO_FILE) {
                    throw new Kwf_Exception_Client(trlKwf("No File uploaded, please select a file."));
                } else if ($file['error'] == UPLOAD_ERR_PARTIAL) {
                    throw new Kwf_Exception_Client(trlKwf("The uploaded file was only partially uploaded."));
                } else {
                    throw new Kwf_Exception("Upload error $file[error]");
                }
            }
            if (!isset($file['tmp_name']) || !is_file($file['tmp_name'])) {
                throw new Kwf_Exception("No File found");
            }
            $maxResolution = (int)$this->_getParam('maxResolution');
            if ($this->_getParam('maxResolution')) {
                $image = getimagesize($file['tmp_name']);
                if (substr($image['mime'], 0, 6) != 'image/') $maxResolution = 0;
            }
            if ($maxResolution > 0) {
                $fileData = Kwf_Media_Image::scale($file['tmp_name'], array('width' => $maxResolution, 'height' => $maxResolution, 'scale' => Kwf_Media_Image::SCALE_BESTFIT));
                $filename = substr($file['name'], 0, strrpos($file['name'], '.'));
                $extension = substr(strrchr($file['name'], '.'), 1);
                $fileRow->verifyUpload($file);
                $fileRow->writeFile($fileData, $filename, $extension, $file['type']);
            } else {
                $fileRow->uploadFile($file);
            }
        } else if (isset($_SERVER['HTTP_X_UPLOAD_NAME'])) {
            $fileData = file_get_contents("php://input");
            if ($_SERVER['CONTENT_LENGTH'] != $_SERVER['HTTP_X_UPLOAD_SIZE']) {
                throw new Kwf_Exception("Content-Length doesn't match X-Upload-Size");
            }
            if ($_SERVER['CONTENT_LENGTH'] != strlen($fileData)) {<commit_msg>try to use HTTP_CONTENT_LENGTH if CONTENT_LENGTH is not set<commit_after><?php
class Kwf_Controller_Action_Media_UploadController extends Kwf_Controller_Action
{
    public function jsonUploadAction()
    {
        $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')
            ->createRow();

        if (isset($_FILES['Filedata'])) {
            $file = $_FILES['Filedata'];
            if ($file['error']) {
                if ($file['error'] == UPLOAD_ERR_NO_FILE) {
                    throw new Kwf_Exception_Client(trlKwf("No File uploaded, please select a file."));
                } else if ($file['error'] == UPLOAD_ERR_PARTIAL) {
                    throw new Kwf_Exception_Client(trlKwf("The uploaded file was only partially uploaded."));
                } else {
                    throw new Kwf_Exception("Upload error $file[error]");
                }
            }
            if (!isset($file['tmp_name']) || !is_file($file['tmp_name'])) {
                throw new Kwf_Exception("No File found");
            }
            $maxResolution = (int)$this->_getParam('maxResolution');
            if ($this->_getParam('maxResolution')) {
                $image = getimagesize($file['tmp_name']);
                if (substr($image['mime'], 0, 6) != 'image/') $maxResolution = 0;
            }
            if ($maxResolution > 0) {
                $fileData = Kwf_Media_Image::scale($file['tmp_name'], array('width' => $maxResolution, 'height' => $maxResolution, 'scale' => Kwf_Media_Image::SCALE_BESTFIT));
                $filename = substr($file['name'], 0, strrpos($file['name'], '.'));
                $extension = substr(strrchr($file['name'], '.'), 1);
                $fileRow->verifyUpload($file);
                $fileRow->writeFile($fileData, $filename, $extension, $file['type']);
            } else {
                $fileRow->uploadFile($file);
            }
        } else if (isset($_SERVER['HTTP_X_UPLOAD_NAME'])) {
            $fileData = file_get_contents("php://input");
            if (isset($_SERVER['CONTENT_LENGTH'])) {
                $contentLength = $_SERVER['CONTENT_LENGTH'];
            } else {
                $contentLength = $_SERVER['HTTP_CONTENT_LENGTH'];
            }
            if ($contentLength != $_SERVER['HTTP_X_UPLOAD_SIZE']) {
                throw new Kwf_Exception("Content-Length doesn't match X-Upload-Size");
            }
            if ($contentLength != strlen($fileData)) {
{'fraction_non_alphanumeric': 0.15350032113037893, 'fraction_numerical': 0.002569043031470777, 'mean_word_length': 2.2220689655172414, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2360363', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1296, 'n_words': 237}