예제 #1
0
파일: plupload.php 프로젝트: kilianr/phpbb
 /**
  * Plupload allows for chunking so we must check for that and assemble
  * the whole file first before performing any checks on it.
  *
  * @param string $form_name The name of the file element in the upload form
  *
  * @return array|null	null if there are no chunks to piece together
  *						otherwise array containing the path to the
  *						pieced-together file and its size
  */
 public function handle_upload($form_name)
 {
     $chunks_expected = $this->request->variable('chunks', 0);
     // If chunking is disabled or we are not using plupload, just return
     // and handle the file as usual
     if ($chunks_expected < 2) {
         return;
     }
     $file_name = $this->request->variable('name', '');
     $chunk = $this->request->variable('chunk', 0);
     $this->user->add_lang('plupload');
     $this->prepare_temporary_directory();
     $file_path = $this->temporary_filepath($file_name);
     $this->integrate_uploaded_file($form_name, $chunk, $file_path);
     // If we are done with all the chunks, strip the .part suffix and then
     // handle the resulting file as normal, otherwise die and await the
     // next chunk.
     if ($chunk == $chunks_expected - 1) {
         rename("{$file_path}.part", $file_path);
         // Reset upload directories to defaults once completed
         $this->set_default_directories();
         // Need to modify some of the $_FILES values to reflect the new file
         return array('tmp_name' => $file_path, 'name' => $this->request->variable('real_filename', ''), 'size' => filesize($file_path), 'type' => $this->mimetype_guesser->guess($file_path, $file_name));
     } else {
         $json_response = new \phpbb\json_response();
         $json_response->send(array('jsonrpc' => '2.0', 'id' => 'id', 'result' => null));
     }
 }
 /**
  * Get mimetype
  *
  * @param string $filename Filename that needs to be checked
  * @return string Mimetype of supplied filename
  */
 function get_mimetype($filename)
 {
     if ($this->mimetype_guesser !== null) {
         $mimetype = $this->mimetype_guesser->guess($filename, $this->uploadname);
         if ($mimetype !== 'application/octet-stream') {
             $this->mimetype = $mimetype;
         }
     }
     return $this->mimetype;
 }