/** * Function to return the proper header type from a file's extension * some of the code extracted gratefully from http://us3.php.net/manual/en/function.fread.php#72716 * @param string $file the file''s name * @param string $ext the file''s (possible forced) extension -- lower case. If null/empty it is not used. * @param string $mime_type the file''s mime type. Defaults to null. * Will be overidden if $ext is not empty * @returns array of string. the headers; */ public function doHeader($file, $ext, $content, $apdContent) { $headers = array(); if (!$content) { if ($ext) { $content = I2CE_MimeTypes::extToMimeType($ext); } if (!$content) { I2CE::raiseError("No mime type identified for ({$file})", E_USER_NOTICE); $content = "application/force-download"; } } if ($apdContent) { $content .= "; " . $apdContent; } $headers[] = "Content-Type: " . $content; $headers[] = "Content-disposition: inline; filename=\"{$file}\""; return $headers; }
public function setFromData($data, $file_name, $mime_type = false, $fmod_time = false) { $content_length = strlen($data); $this->value = rtrim($data, ""); //MDB2 strips off terminating \0 when returning results $this->null_term = $content_length - strlen($this->value); $this->file_name = $file_name; if ($fmod_time == false) { $this->fmod_time = time(); } else { $fmod_time = $fmod_time; } $this->mime_type = $mime_type; if (!$this->mime_type || $this->mime_type == 'application/unknown' || $this->mime_type == 'application/x-download') { $this->mime_type = I2CE_MimeTypes::magicMimeType($this->value); } if (!$this->isValidMimeType($this->mime_type)) { //let's try to get it from the extension of the uploaded file if (($pos = strrpos($file_name, '.')) !== false) { $ext = substr($file_name, $pos + 1); $this->mime_type = I2CE_MimeTypes::extToMimeType($ext); if (!$this->isValidMimeType($this->mime_type)) { I2CE::raiseError("Unable to upload file {$file_name}, Invalid mime type from extension"); $this->file_name = false; $this->fmod_time = false; $this->mime_type = false; $this->value = false; $this->null_term = 0; return; } } else { I2CE::raiseError("Unable to set file {$file_name}, Invalid mime type"); $this->file_name = false; $this->fmod_time = false; $this->mime_type = false; $this->value = false; $this->null_term = 0; return; } } }