本文整理汇总了PHP中FileUtil::isBinary方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::isBinary方法的具体用法?PHP FileUtil::isBinary怎么用?PHP FileUtil::isBinary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtil
的用法示例。
在下文中一共展示了FileUtil::isBinary方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Creates a new attachments.
*
* @param string $file
* @param array $attachmentData
* @return AttachmentEditor
*/
public static function create($file, $attachmentData)
{
$attachmentData['isBinary'] = 1;
if (!$attachmentData['isImage']) {
$attachmentData['isBinary'] = (int) FileUtil::isBinary($file);
}
// insert attachment
$attachmentID = self::insert($attachmentData);
$attachmentData['attachmentID'] = $attachmentID;
$attachment = new AttachmentEditor(null, $attachmentData);
// copy tmp file to /attachments folders
try {
$path = WCF_DIR . 'attachments/attachment-' . $attachmentID;
if (!@move_uploaded_file($file, $path)) {
throw new SystemException();
}
@chmod($path, 0777);
} catch (SystemException $e) {
// could not copy uploaded file, rollback insert statement
$attachment->delete();
return null;
}
return $attachment;
}
示例2: setAttachment
/**
* Saves an attachment in database and in the folder /attachments.
* Creates a thumbnail, if necessary.
*
* @param array $attachment
* @return boolean false, if storage fails
*/
public function setAttachment(&$attachment)
{
$attachment['isBinary'] = 1;
if (!$attachment['isImage']) {
$attachment['isBinary'] = (int) FileUtil::isBinary($attachment['attachment']);
}
// insert attachment
$attachmentID = self::insert($attachment['attachmentName'], array('packageID' => $this->packageID, 'containerID' => $attachment['messageID'], 'containerType' => $this->messageType, 'userID' => $attachment['userID'], 'attachmentSize' => $attachment['attachmentSize'], 'isImage' => $attachment['isImage'], 'sha1Hash' => $attachment['sha1Hash'], 'idHash' => $attachment['idHash'], 'uploadTime' => $attachment['uploadTime'], 'fileType' => $attachment['fileType'], 'isBinary' => $attachment['isBinary'], 'showOrder' => $attachment['showOrder']));
$attachment['attachmentID'] = $attachmentID;
// copy tmp file to /attachments folders
try {
$path = WCF_DIR . 'attachments/attachment-' . $attachmentID;
if (!@move_uploaded_file($attachment['attachment'], $path)) {
throw new SystemException();
} else {
// change attachment file path
$attachment['attachment'] = $path;
@chmod($path, 0777);
}
} catch (SystemException $e) {
// could not copy uploaded file, rollback insert statement
$this->delete($attachmentID);
return false;
}
// create thumbnail
if (ATTACHMENT_ENABLE_THUMBNAILS && $attachment['isImage']) {
$this->saveThumbnail($attachment, $this->thumbnailWidth, $this->thumbnailHeight, $this->addSourceInfo, $this->useEmbedded);
}
return true;
}