/** * @return array */ public function uploadFromFile() { $webRequest = $this->getContext()->getRequest(); $uploader = new UploadFromFile(); $uploader->initialize($webRequest->getFileName('file'), $webRequest->getUpload('file')); $verified = $uploader->verifyUpload(); if ($verified['status'] == 0 || $verified['status'] == 10) { return [$uploader->getTempPath(), true]; } else { return [$uploader->getTempPath(), false, $this->getUploadFileErrorMessage($uploader, $verified)]; } }
protected function uploadImage() { global $wgImageMagickConvertCommand, $wgServer; $request = $this->getRequest(); $result = array(); $fromPage = $request->getVal('viapage'); // sanity check on the page to link to $title = Title::newFromText($fromPage, NS_MAIN); if (!$title->exists()) { $result['error'] = "Error: No article {$fromPage} found to link image."; return $result; } // try to get a unique file name by appending a suffix and the current time to the save name here $dateTime = new DateTime(); $webUpload = $request->getUpload('wpUploadImage'); $info = new SplFileInfo($webUpload->getName()); $ext = $info->getExtension(); $info = new SplFileInfo($request->getVal("name")); for ($i = 0; $i < 100; $i++) { $saveName = "User Completed Image {$fromPage} {$dateTime->format('Y.m.d H.i.s')}.{$i}.{$ext}"; $title = Title::newFromText($saveName, NS_IMAGE); if (!$title->getArticleID()) { break; } } // if the title still exists, show an error if ($title->getArticleID()) { $result['error'] = 'file with this name already exists'; return $result; } $upload = new UploadFromFile(); $upload->initialize($saveName, $webUpload); $verification = $upload->verifyUpload(); if ($verification['status'] !== UploadBase::OK) { $result['error'] = "verification error: " . $verification['status']; return $result; } $warnings = $upload->checkWarnings(); if ($warnings) { $result['warnings'] = $warnings; // todo this should be toggled on off for testings perhaps // since it might get kind of annoying if ($warnings['duplicate']) { $result['debug'][] = $warnings['duplicate-archive']; $result['error'] = "this file was already uploaded"; return $result; } } $comment = '{{Self}}'; $status = $upload->performUpload($comment, '', true, $this->getUser()); if (!$status->isGood()) { $error = $status->getErrorsArray(); $result['error'] = 'perform upload error: ' . $error; return $result; } $upload->cleanupTempFile(); // todo - do this part after the single file upload // Image orientation is a bit wonky on some mobile devices; use ImageMagick's auto-orient to try fixing it. //$tempFilePath = $temp_file->getPath(); //$cmd = $wgImageMagickConvertCommand . ' ' . $tempFilePath . ' -auto-orient ' . $tempFilePath; //exec($cmd); $file = $upload->getLocalFile(); $thumb = $file->getThumbnail(200, -1, true, true); if (!$thumb) { $result['error'] = 'file thumbnail does not exist'; $file->delete(''); return $result; } $fileTitle = $file->getTitle(); $result['titleText'] = $fileTitle->getText(); $result['titleDBkey'] = substr($fileTitle->getDBkey(), 21); // Only keep important info $result['titlePreText'] = '/' . $fileTitle->getPrefixedText(); $result['titleArtID'] = $fileTitle->getArticleID(); $result['timestamp'] = wfTimestamp(TS_MW); $result['fromPage'] = $request->getVal('viapage'); $result['thumbURL'] = $thumb->getUrl(); $result['fileURL'] = $wgServer . $file->getUrl(); $this->addToDB($result); return $result; }
//Dateinamen überprüfen ob indiziert werden soll #wfFileIndexer($filename,false); if (class_exists('FileIndexer')) { $fi = new FileIndexer(); $fi = $fi->checkFileType($filename); if ($fi == true) { if (isset($_POST['fi'][$ids])) { $sCreateIndexFilepath = true; } } } if (isset($_POST['kat'][$ids])) { #kategorie gesetzt $comment = "[[" . $_POST['kat_hidden'] . "]]"; } $mUpload->initialize($filename, $_FILES['Filedata']['tmp_name'], $_FILES['Filedata']['size']); } //if isset $permErrors = $mUpload->verifyPermissions($wgUser); if ($permErrors !== true) { $error = "missing permissions"; print_r($permErrors); } $verification = $mUpload->verifyUpload(); #print_r($verification['status']); /* if ( $verification['status'] !== UploadBase::OK ) { $result['result'] = 'Failure'; switch( $verification['status'] ) { case UploadBase::EMPTY_FILE: