/** * Remove a temporarily kept file stashed by saveTempUploadedFile(). * * @return Boolean: success */ protected function unsaveUploadedFile() { if ( !( $this->mUpload instanceof UploadFromStash ) ) { return true; } $success = $this->mUpload->unsaveUploadedFile(); if ( !$success ) { $this->getOutput()->showFileDeleteError( $this->mUpload->getTempPath() ); return false; } else { return true; } }
/** * Verifies image being uploaded whether it's not corrupted * * @author macbre * * @param UploadBase $upload * @param string $mime * @param array $error * @return bool */ public static function onUploadVerifyFile(UploadBase $upload, $mime, &$error) { // only check supported images $mimeTypes = array('image/gif', 'image/jpeg', 'image/png'); if (!in_array($mime, $mimeTypes)) { return true; } // validate an image using ImageMagick $imageFile = $upload->getTempPath(); $output = wfShellExec("identify -regard-warnings {$imageFile} 2>&1", $retVal); wfDebug("Exit code #{$retVal}\n{$output}\n"); $isValid = $retVal === 0; if (!$isValid) { Wikia::log(__METHOD__, 'failed', rtrim($output), true); // pass an error to UploadBase class $error = array('verification-error'); } return $isValid; }
private function getTempPath(UploadBase $upload_base) { $temp_path = $upload_base->getTempPath(); if ($temp_path === '' || $temp_path === null) { throw new \Exception('newmanuscript-error-nofile'); } return $temp_path; }