Merge pull request #22 from radiorabe/feature/use-zend-file-transfer-for-plupload

Use Zend_File_Transfer instead of $_FILES
This commit is contained in:
Robb 2017-03-04 22:15:19 -05:00 committed by GitHub
commit 6085a8fd27
2 changed files with 15 additions and 3 deletions

View File

@ -92,8 +92,8 @@ class CcFiles extends BaseCcFiles {
//Extract the original filename, which we set as the temporary title for the track
//until it's finished being processed by the analyzer.
$originalFilename = $_FILES["file"]["name"];
$tempFilePath = $_FILES['file']['tmp_name'];
$originalFilename = $fileArray['file']['name'];
$tempFilePath = $fileArray['file']['tmp_name'];
try {
return self::createAndImport($fileArray, $tempFilePath, $originalFilename);

View File

@ -129,7 +129,19 @@ class Rest_MediaController extends Zend_Rest_Controller
}
try {
$sanitizedFile = CcFiles::createFromUpload($this->getRequest()->getPost());
// REST uploads are not from Zend_Form, hence we handle them using Zend_File_transfer directly
$upload = new Zend_File_Transfer();
// this error should not really get hit, letting the user know if it does is nice for debugging
// see: https://github.com/LibreTime/libretime/issues/3#issuecomment-281143417
if (!$upload->isValid('file')) {
throw new Exception("invalid file uploaded");
}
$fileInfo = $upload->getFileInfo('file');
// this should have more info on any actual faults detected by php
if ($fileInfo['file']['error']) {
throw new Exception(sprintf('File upload error: %s', $fileInfo['file']['error']));
}
$sanitizedFile = CcFiles::createFromUpload($fileInfo);
$this->getResponse()
->setHttpResponseCode(201)
->appendBody(json_encode($sanitizedFile));