当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP::getMimeType方法代码示例

本文整理汇总了PHP中HTTP::getMimeType方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::getMimeType方法的具体用法?PHP HTTP::getMimeType怎么用?PHP HTTP::getMimeType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTP的用法示例。


在下文中一共展示了HTTP::getMimeType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: send_file

 /**
  * Construct an SS_HTTPResponse that will deliver a file to the client
  */
 static function send_file($fileData, $fileName, $mimeType = null)
 {
     if (!$mimeType) {
         $mimeType = HTTP::getMimeType($fileName);
     }
     $response = new SS_HTTPResponse($fileData);
     $response->addHeader("Content-Type", "{$mimeType}; name=\"" . addslashes($fileName) . "\"");
     $response->addHeader("Content-disposition", "attachment; filename=" . addslashes($fileName));
     $response->addHeader("Content-Length", strlen($fileData));
     $response->addHeader("Pragma", "");
     // Necessary because IE has issues sending files over SSL
     return $response;
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:16,代码来源:HTTPRequest.php

示例2: streamObject

 /**
  *
  * @param String $fileRef
  *			The "FileRef" property of an object to stream the content of
  */
 public function streamObject(SharePointContentItem $object, $toFile = '', $contentType = '')
 {
     $contentUrl = $this->url . '/' . str_replace('%2F', '/', rawurlencode($object->FileRef));
     $contentType = HTTP::getMimeType($object->FileRef);
     if (!$contentType) {
         $contentType = 'application/octet-stream';
     }
     $session = curl_init($contentUrl);
     curl_setopt($session, CURLOPT_USERPWD, $this->username . ':' . $this->password);
     curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
     if (!strlen($toFile)) {
         $filename = rawurlencode($object->LinkFilename);
         header("Content-Disposition: atachment; filename={$filename}");
         header("Content-Type: {$contentType}");
         // header("Content-Length: ".filesize("$path/$filename"));
         header("Pragma: no-cache");
         header("Expires: 0");
         curl_exec($session);
     } else {
         // get the file and store it into a local item
         curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($session);
         $fp = fopen($toFile, 'w');
         if (!$fp) {
             throw new Exception("Could not write file to {$toFile}");
         }
         fwrite($fp, $response);
         fclose($fp);
     }
     curl_close($session);
 }
开发者ID:nyeholt,项目名称:silverstripe-sharepoint-connector,代码行数:36,代码来源:SharePointClient.php

示例3: streamContent

 /**
  * Stream to browser or file
  *
  * @param string $toFile 
  */
 public function streamContent($toFile = null)
 {
     $contentType = HTTP::getMimeType($this->Filename);
     // now get the file
     $contentUrl = $this->getSource()->ApiUrl . '/' . $this->Filename;
     $session = curl_init($contentUrl);
     if (!strlen($toFile)) {
         // QUICK HACK
         $n = $this->name;
         $filename = rawurlencode($n);
         header("Content-Disposition: atachment; filename={$filename}");
         header("Content-Type: {$contentType}");
         // header("Content-Length: ".filesize("$path/$filename"));
         header("Pragma: no-cache");
         header("Expires: 0");
         curl_exec($session);
     } else {
         // get the file and store it into a local item
         curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
         $response = curl_exec($session);
         $fp = fopen($toFile, 'w');
         if (!$fp) {
             throw new Exception("Could not write file to {$toFile}");
         }
         fwrite($fp, $response);
         fclose($fp);
     }
     curl_close($session);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-silverstripe-connector,代码行数:34,代码来源:SilverStripeContentItem.php

示例4: send_file

 /**
  * Construct an SS_HTTPResponse that will deliver a file to the client
  */
 static function send_file($fileData, $fileName, $mimeType = null)
 {
     if (!$mimeType) {
         $mimeType = HTTP::getMimeType($fileName);
     }
     $response = new SS_HTTPResponse($fileData);
     $response->addHeader("Content-Type", "{$mimeType}; name=\"" . addslashes($fileName) . "\"");
     $response->addHeader("Content-disposition", "attachment; filename=" . addslashes($fileName));
     $response->addHeader("Content-Length", strlen($fileData));
     $response->addHeader("Pragma", "");
     // Necessary because IE has issues sending files over SSL
     if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") == true) {
         $response->addHeader('Cache-Control', 'max-age=3, must-revalidate');
         // Workaround for IE6 and 7
     }
     return $response;
 }
开发者ID:rixrix,项目名称:sapphire,代码行数:20,代码来源:HTTPRequest.php

示例5: process

 /**
  * Process the form that is submitted through the site
  * 
  * @param Array Data
  * @param Form Form 
  * @return Redirection
  */
 function process($data, $form)
 {
     Session::set("FormInfo.{$form->FormName()}.data", $data);
     Session::clear("FormInfo.{$form->FormName()}.errors");
     foreach ($this->Fields() as $field) {
         $messages[$field->Name] = $field->getErrorMessage()->HTML();
         if ($field->Required) {
             if (!isset($data[$field->Name]) || !$data[$field->Name] || !$field->getFormField()->validate($this->validator)) {
                 $form->addErrorMessage($field->Name, $field->getErrorMessage()->HTML(), 'bad');
             }
         }
     }
     if (Session::get("FormInfo.{$form->FormName()}.errors")) {
         Director::redirectBack();
         return;
     }
     $submittedForm = Object::create('SubmittedForm');
     $submittedForm->SubmittedByID = ($id = Member::currentUserID()) ? $id : 0;
     $submittedForm->ParentID = $this->ID;
     // if saving is not disabled save now to generate the ID
     if (!$this->DisableSaveSubmissions) {
         $submittedForm->write();
     }
     $values = array();
     $attachments = array();
     $submittedFields = new DataObjectSet();
     foreach ($this->Fields() as $field) {
         if (!$field->showInReports()) {
             continue;
         }
         $submittedField = $field->getSubmittedFormField();
         $submittedField->ParentID = $submittedForm->ID;
         $submittedField->Name = $field->Name;
         $submittedField->Title = $field->getField('Title');
         // save the value from the data
         if ($field->hasMethod('getValueFromData')) {
             $submittedField->Value = $field->getValueFromData($data);
         } else {
             if (isset($data[$field->Name])) {
                 $submittedField->Value = $data[$field->Name];
             }
         }
         if (!empty($data[$field->Name])) {
             if (in_array("EditableFileField", $field->getClassAncestry())) {
                 if (isset($_FILES[$field->Name])) {
                     // create the file from post data
                     $upload = new Upload();
                     $file = new File();
                     $file->ShowInSearch = 0;
                     $upload->loadIntoFile($_FILES[$field->Name], $file);
                     // write file to form field
                     $submittedField->UploadedFileID = $file->ID;
                     // attach a file only if lower than 1MB
                     if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
                         $attachments[] = $file;
                     }
                 }
             }
         }
         if (!$this->DisableSaveSubmissions) {
             $submittedField->write();
         }
         $submittedFields->push($submittedField);
     }
     $emailData = array("Sender" => Member::currentUser(), "Fields" => $submittedFields);
     // email users on submit.
     if ($this->EmailRecipients()) {
         $email = new UserDefinedForm_SubmittedFormEmail($submittedFields);
         $email->populateTemplate($emailData);
         if ($attachments) {
             foreach ($attachments as $file) {
                 if ($file->ID != 0) {
                     $email->attachFile($file->Filename, $file->Filename, HTTP::getMimeType($file->Filename));
                 }
             }
         }
         foreach ($this->EmailRecipients() as $recipient) {
             $email->populateTemplate($recipient);
             $email->populateTemplate($emailData);
             $email->setFrom($recipient->EmailFrom);
             $email->setBody($recipient->EmailBody);
             $email->setSubject($recipient->EmailSubject);
             $email->setTo($recipient->EmailAddress);
             // check to see if they are a dynamic sender. eg based on a email field a user selected
             if ($recipient->SendEmailFromField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
                 if ($submittedFormField) {
                     $email->setFrom($submittedFormField->Value);
                 }
             }
             // check to see if they are a dynamic reciever eg based on a dropdown field a user selected
             if ($recipient->SendEmailToField()) {
                 $submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
//.........这里部分代码省略.........
开发者ID:notioncollective,项目名称:silverstripe-userforms,代码行数:101,代码来源:UserDefinedForm.php

示例6: send_file

	/**
	 * Construct an HTTPResponse that will deliver a file to the client
	 */
	static function send_file($fileData, $fileName, $mimeType = null) {
		if(!$mimeType) $mimeType = HTTP::getMimeType($fileName);

		$response = new HTTPResponse($fileData);
		$response->addHeader("Content-Type", "$mimeType; name=\"" . addslashes($fileName) . "\"");
		$response->addHeader("Content-disposition", "attachment; filename=" . addslashes($fileName));
		$response->addHeader("Content-Length", strlen($fileData));
		
		return $response;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:13,代码来源:HTTPRequest.php

示例7: fileFound

 /**
  * File found response
  *
  * @param $file File to send
  * @param $alternate_path string If supplied, return the file from this path instead, for
  * example, resampled images.
  */
 function fileFound(File $file, $alternate_path = null)
 {
     // File properties
     $file_name = $file->Name;
     $file_path = Director::getAbsFile($alternate_path ? $alternate_path : $file->FullPath);
     $file_size = filesize($file_path);
     // Testing mode - return an HTTPResponse
     if (self::$use_ss_sendfile) {
         if (ClassInfo::exists('SS_HTTPRequest')) {
             return SS_HTTPRequest::send_file(file_get_contents($file_path), $file_name);
         } else {
             return HTTPRequest::send_file(file_get_contents($file_path), $file_name);
         }
     }
     // Normal operation:
     $mimeType = HTTP::getMimeType($file_name);
     header("Content-Type: {$mimeType}; name=\"" . addslashes($file_name) . "\"");
     header("Content-Disposition: attachment; filename=" . addslashes($file_name));
     header("Cache-Control: max-age=1, private");
     header("Content-Length: {$file_size}");
     header("Pragma: ");
     if (self::$use_x_sendfile) {
         session_write_close();
         header('X-Sendfile: ' . $file_path);
         exit;
     } elseif ($filePointer = @fopen($file_path, 'rb')) {
         session_write_close();
         $this->flush();
         // Push the file while not EOF and connection exists
         while (!feof($filePointer) && !connection_aborted()) {
             print fread($filePointer, 1024 * self::$chunck_size_kb);
             $this->flush();
         }
         fclose($filePointer);
         exit;
     } else {
         // Edge case - either not found anymore or can't read
         return $this->fileNotFound();
     }
 }
开发者ID:hamishcampbell,项目名称:silverstripe-securefiles,代码行数:47,代码来源:SecureFileController.php


注:本文中的HTTP::getMimeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。