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:
commit
6085a8fd27
|
@ -92,8 +92,8 @@ class CcFiles extends BaseCcFiles {
|
||||||
|
|
||||||
//Extract the original filename, which we set as the temporary title for the track
|
//Extract the original filename, which we set as the temporary title for the track
|
||||||
//until it's finished being processed by the analyzer.
|
//until it's finished being processed by the analyzer.
|
||||||
$originalFilename = $_FILES["file"]["name"];
|
$originalFilename = $fileArray['file']['name'];
|
||||||
$tempFilePath = $_FILES['file']['tmp_name'];
|
$tempFilePath = $fileArray['file']['tmp_name'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return self::createAndImport($fileArray, $tempFilePath, $originalFilename);
|
return self::createAndImport($fileArray, $tempFilePath, $originalFilename);
|
||||||
|
|
|
@ -129,7 +129,19 @@ class Rest_MediaController extends Zend_Rest_Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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()
|
$this->getResponse()
|
||||||
->setHttpResponseCode(201)
|
->setHttpResponseCode(201)
|
||||||
->appendBody(json_encode($sanitizedFile));
|
->appendBody(json_encode($sanitizedFile));
|
||||||
|
|
Loading…
Reference in New Issue