本文整理汇总了PHP中ezcMailTools::guessContentType方法的典型用法代码示例。如果您正苦于以下问题:PHP ezcMailTools::guessContentType方法的具体用法?PHP ezcMailTools::guessContentType怎么用?PHP ezcMailTools::guessContentType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ezcMailTools
的用法示例。
在下文中一共展示了ezcMailTools::guessContentType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGuessContentType
public function testGuessContentType()
{
$fileNames = array('/home/1.jpg', '2.jpe', '3.jpeg', '4.gif', '5.tif', '6.tiff', '7.bmp', '8.png', '9.xxx', '10');
$types = array('image/jpeg', 'image/jpeg', 'image/jpeg', 'image/gif', 'image/tiff', 'image/tiff', 'image/bmp', 'image/png', '/', '/');
for ($i = 0; $i < count($fileNames); $i++) {
$contentType = null;
$mimeType = null;
ezcMailTools::guessContentType($fileNames[$i], $contentType, $mimeType);
$this->assertEquals($types[$i], $contentType . '/' . $mimeType);
}
}
示例2: generateHtmlPart
/**
* Returns an ezcMailPart based on the HTML provided.
*
* This method adds local files/images to the mail itself using a
* {@link ezcMailMultipartRelated} object.
*
* @throws ezcBaseFileNotFoundException
* if $fileName does not exists.
* @throws ezcBaseFilePermissionProblem
* if $fileName could not be read.
* @return ezcMailPart
*/
private function generateHtmlPart()
{
$result = false;
if ($this->htmlText != '') {
$matches = array();
if ($this->options->automaticImageInclude === true) {
// recognize file:// and file:///, pick out the image, add it as a part and then..:)
preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
// pictures/files can be added multiple times. We only need them once.
$matches = array_unique($matches[1]);
}
$result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
$result->subType = "html";
if (count($matches) > 0) {
$htmlPart = $result;
// wrap already existing message in an alternative part
$result = new ezcMailMultipartRelated($result);
// create a filepart and add it to the related part
// also store the ID for each part since we need those
// when we replace the originals in the HTML message.
foreach ($matches as $fileName) {
if (is_readable($fileName)) {
// @todo waiting for fix of the fileinfo extension
// $contents = file_get_contents( $fileName );
$mimeType = null;
$contentType = null;
if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
// if fileinfo extension is available
$filePart = new ezcMailFile($fileName);
} elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
// if fileinfo extension is not available try to get content/mime type
// from the file extension
$filePart = new ezcMailFile($fileName, $contentType, $mimeType);
} else {
// fallback in case fileinfo is not available and could not get content/mime
// type from file extension
$filePart = new ezcMailFile($fileName, "application", "octet-stream");
}
$cid = $result->addRelatedPart($filePart);
// replace the original file reference with a reference to the cid
$this->htmlText = str_replace('file://' . $fileName, 'cid:' . $cid, $this->htmlText);
} else {
if (file_exists($fileName)) {
throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
} else {
throw new ezcBaseFileNotFoundException($fileName);
}
// throw
}
}
// update mail, with replaced URLs
$htmlPart->text = $this->htmlText;
}
}
return $result;
}
示例3: generateHtmlPart
/**
* Returns an ezcMailPart based on the HTML provided.
*
* This method adds local files/images to the mail itself using a
* {@link ezcMailMultipartRelated} object.
*
* @throws ezcBaseFileNotFoundException
* if $fileName does not exists.
* @throws ezcBaseFilePermissionProblem
* if $fileName could not be read.
* @return ezcMailPart
*/
private function generateHtmlPart()
{
$result = false;
if ($this->htmlText != '') {
$matches = array();
if ($this->options->automaticImageInclude === true) {
/*
1.7.1 regex is buggy filename are not extract correctly
http://issues.ez.no/IssueView.php?Id=16612&
preg_match_all( '(
<img \\s+[^>]*
src\\s*=\\s*
(?:
(?# Match quoted attribute)
([\'"])file://(?P<quoted>[^>]+)\\1
(?# Match unquoted attribute, which may not contain spaces)
| file://(?P<unquoted>[^>\\s]+)
)
[^>]* >)ix', $htmlText, $matches );
* */
// CJW Newsletter regex change only find all file://ezroot/
// so it is secure
// recognize file://ezroot/ and pick out the image, add it as a part and then..:)
preg_match_all("/<img[\\s\\*\\s]src=[\\'\"]file:\\/\\/ezroot\\/([^ >\\'\"]+)/i", $this->htmlText, $matches);
// pictures/files can be added multiple times. We only need them once.
$matches = array_unique($matches[1]);
}
$result = new ezcMailText($this->htmlText, $this->charset, $this->encoding);
$result->subType = "html";
if (count($matches) > 0) {
$htmlPart = $result;
// wrap already existing message in an alternative part
$result = new ezcMailMultipartRelated($result);
// create a filepart and add it to the related part
// also store the ID for each part since we need those
// when we replace the originals in the HTML message.
foreach ($matches as $fileName) {
if (is_readable($fileName)) {
// @todo waiting for fix of the fileinfo extension
// $contents = file_get_contents( $fileName );
$mimeType = null;
$contentType = null;
if (ezcBaseFeatures::hasExtensionSupport('fileinfo')) {
// if fileinfo extension is available
$filePart = new ezcMailFile($fileName);
} elseif (ezcMailTools::guessContentType($fileName, $contentType, $mimeType)) {
// if fileinfo extension is not available try to get content/mime type
// from the file extension
$filePart = new ezcMailFile($fileName, $contentType, $mimeType);
} else {
// fallback in case fileinfo is not available and could not get content/mime
// type from file extension
$filePart = new ezcMailFile($fileName, "application", "octet-stream");
}
$cid = $result->addRelatedPart($filePart);
// replace the original file reference with a reference to the cid
$this->htmlText = str_replace('file://ezroot/' . $fileName, 'cid:' . $cid, $this->htmlText);
} else {
if (file_exists($fileName)) {
throw new ezcBaseFilePermissionException($fileName, ezcBaseFileException::READ);
} else {
throw new ezcBaseFileNotFoundException($fileName);
}
// throw
}
}
// update mail, with replaced URLs
$htmlPart->text = $this->htmlText;
}
}
return $result;
}