/** * @deprecated use Kwf_Uploads_Model::verifyUpload instead */ public function verifyUpload($filedata) { return Kwf_Uploads_Model::verifyUpload($filedata); }
public function jsonUploadAction() { Kwf_Util_MemoryLimit::set(1024); $uploadModel = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model'); $uploadedFile = array('filename' => '', 'extension' => ''); 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 { if ($file['error'] == UPLOAD_ERR_INI_SIZE) { throw new Kwf_Exception_Client(trlKwf("The uploaded file is too large.")); } 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; } } $filename = substr($file['name'], 0, strrpos($file['name'], '.')); $extension = substr(strrchr($file['name'], '.'), 1); $uploadedFile['filename'] = $filename; $uploadedFile['extension'] = $extension; if ($maxResolution > 0) { $fileData = Kwf_Media_Image::scale($file['tmp_name'], array('width' => $maxResolution, 'height' => $maxResolution, 'cover' => false)); Kwf_Uploads_Model::verifyUpload($file); $fileRow = $uploadModel->writeFile($fileData, $filename, $extension, $file['type']); } else { $fileRow = $uploadModel->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)) { throw new Kwf_Exception("Content-Length doesn't match uploaded data"); } $name = rawurldecode($_SERVER['HTTP_X_UPLOAD_NAME']); $filename = substr($name, 0, strrpos($name, '.')); $extension = substr(strrchr($name, '.'), 1); $uploadedFile['filename'] = $filename; $uploadedFile['extension'] = $extension; $mimeType = null; if (isset($_SERVER['HTTP_X_UPLOAD_TYPE'])) { $mimeType = $_SERVER['HTTP_X_UPLOAD_TYPE']; } if (isset($_SERVER['HTTP_X_UPLOAD_MAXRESOLUTION']) && $_SERVER['HTTP_X_UPLOAD_MAXRESOLUTION'] > 0) { $maxResolution = $_SERVER['HTTP_X_UPLOAD_MAXRESOLUTION']; $tempFile = tempnam('temp', 'upload'); file_put_contents($tempFile, $fileData); $fileData = Kwf_Media_Image::scale($tempFile, array('width' => $maxResolution, 'height' => $maxResolution, 'cover' => false)); unlink($tempFile); $fileRow = $uploadModel->writeFile($fileData, $filename, $extension, $mimeType); } else { $fileRow = $uploadModel->writeFile($fileData, $filename, $extension, $mimeType); } } else { throw new Kwf_Exception_Client(trlKwf("No Filedata received.")); } } $this->view->value = $fileRow->getFileInfo(); $this->view->value['uploaded_filename'] = $uploadedFile['filename']; $this->view->value['uploaded_extension'] = $uploadedFile['extension']; }