Add e-mail attachment
@return NULL
@param $file string
@param $alias string
@param $cid string
433701
function attach($file,$alias=NULL,$cid=NULL) {
		if (!is_file($file))
			user_error(sprintf(self::E_Attach,$file),E_USER_ERROR);
		if ($alias)
			$file=[$alias,$file];
		$this->attachments[]=['filename'=>$file,'cid'=>$cid];
	}
889164
public function getAttachedFile($file, $attachment_id) {
	    $shouldOverride = apply_filters('ilab_should_override_attached_file', true, $attachment_id);

		if(!file_exists($file) && $shouldOverride) {
			$meta = wp_get_attachment_metadata($attachment_id);

			$new_url = null;
			if($meta) {
				$new_url = $this->getAttachmentURLFromMeta($meta);
			}

			if(!$new_url) {
				$meta = get_post_meta($attachment_id, 'ilab_s3_info', true);
				if($meta) {
					$new_url = $this->getAttachmentURLFromMeta($meta);
				} else if(!$meta && StorageSettings::docCdn()) {
					$post = \WP_Post::get_instance($attachment_id);
					if($post && (strpos($post->guid, StorageSettings::docCdn()) === 0)) {
						$new_url = $post->guid;
					}
				}
			}

			if($new_url) {
				return $new_url;
			}
		}

		return $file;
	}
499064
public function download($target, $alias = null)
    {
        $this->preload($target, $alias);

        // Count file size in bytes
        $size = filesize($target);

        // multipart-download and download resuming support
        if (isset($_SERVER['HTTP_RANGE'])) {

            list($a, $range) = explode("=", $_SERVER['HTTP_RANGE'], 2);
            list($range) = explode(",", $range, 2);
            list($range, $range_end) = explode("-", $range);

            $range = intval($range);

            if (!$range_end) {
                $range_end = $size - 1;
            } else {
                $range_end = intval($range_end);
            }

            $new_length = $range_end - $range + 1;

            $headers = array(
                'Content-Length' => $new_length,
                'Content-Range' => sprintf('bytes %s', $range - $range_end / $size)
            );

            $this->headerBag->setStatusCode(206)
                            ->setPairs($headers)
                            ->send();
        } else {

            $new_length = $size;
            $this->headerBag->appendPair('Content-Length', $size)
                            ->send()
                            ->clear();
        }

        $chunksize = 1024 * 1024;
        $bytes_send = 0;

        $target = fopen($target, 'r');

        if (isset($_SERVER['HTTP_RANGE'])) {
            fseek($target, $range);
        }

        while (!feof($target) && (!connection_aborted()) && ($bytes_send < $new_length)) {

            $buffer = fread($target, $chunksize);
            print($buffer);
            flush();
            $bytes_send += strlen($buffer);
        }

        fclose($target);
    }
952326
public function run( $cid ) {

		$model		= $this->model;
		$gallery	= $this->galleryService->getById( $cid );

		if( isset( $gallery ) && ( $this->direct || $gallery->belongsTo( $model ) ) ) {

			if( $this->maxItems > 0 ) {

				$items = $gallery->files;

				if( count( $items ) >= $this->maxItems ) {

					// Trigger Ajax Failure
					return AjaxUtil::generateFailure( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_REQUEST ), [ 'limit' => "You are not allowed to add more than $this->maxItems items." ] );
				}
			}

			$file = new File();

			$file->siteId = $gallery->siteId;

			if( $file->load( Yii::$app->request->post(), $this->fileName ) && $file->validate() ) {

				$modelFile = $this->galleryService->createItem( $gallery, $file, $this->modelType );

				$file = $modelFile->model;

				$data = [
					'mid' => $modelFile->id, 'fid' => $file->id,
					'name' => $file->name, 'extension' => $file->extension,
					'title' => $file->title, 'caption' => $file->caption,
					'altText' => $file->altText, 'link' => $file->link, 'description' => $file->description,
					'url' => $file->getFileUrl()
				];

				if( $file->type == 'image' ) {

					$data[ 'mediumUrl' ]	= $file->getMediumUrl();
					$data[ 'thumbUrl' ]		= $file->getThumbUrl();
				}

				// Trigger Ajax Success
				return AjaxUtil::generateSuccess( Yii::$app->coreMessage->getMessage( CoreGlobal::MESSAGE_REQUEST ), $data );
			}

			// Generate Errors
			$errors = AjaxUtil::generateErrorMessage( $file );

			// Trigger Ajax Failure
			return AjaxUtil::generateFailure( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_REQUEST ), $errors );
		}

		// Trigger Ajax Failure
		return AjaxUtil::generateFailure( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
	}
157231
public function registerAlias($alias, $file, $extension = null)
    {
        if ($extension === null) {
            $extension = File::extension($file);
        }

        $extension = strtolower($extension);

        if (!isset($this->aliases[$extension])) {
            $this->aliases[$extension] = [];
        }

        $this->aliases[$extension][$alias] = $file;

        return $this;
    }
650107
public function addAttachment($attachment)
    {
        if ($attachment instanceof \SplFileObject && $attachment->isFile() && $attachment->isReadable()) {
            $file['filename'] = method_exists($attachment, 'getAttachmentFilename') ?
                $attachment->getAttachmentFilename() :
                $attachment->getBasename();

            $file['is_embedded'] = method_exists($attachment, 'getIsEmbedded') ? $attachment->getIsEmbedded() : false;
            $file['id'] = method_exists($attachment, 'getId') ? $attachment->getId() : null;

            if (method_exists($attachment, 'getMimeType')) {
                $file['mime_type'] = $attachment->getMimeType();
            } else {
                $resource = finfo_open(FILEINFO_MIME_TYPE);
                $file['mime_type'] = finfo_file($resource, $attachment->getRealPath());
            }

            $file['contents'] = '';
            while (!$attachment->eof()) {
                $file['contents'] .= $attachment->fgets();
            }
            $file['contents'] = base64_encode($file['contents']);

            $this->attachments[] = $file;
        } elseif (is_array($attachment)) {
            $this->attachments[] = $attachment;
        }

        return $this;
    }
441306
public function attachPostFiles($files)
    {
        if (is_array($files)) {
            foreach ($files as $file) {
                // Check whether file has been posted.
                if (is_uploaded_file($file['tmp_name'])) {
                    // Get file from its location.
                    $fileContents = file_get_contents($file['tmp_name']);
                    if ($fileContents) {
                        $this->addAttachment(
                                $file['name'], $file['type'], $fileContents
                        );
                    } else {
                        throw new Exception('Empty attachment');
                    }
                } else {
                    switch ($file['error']) {
                        case 0:
                            throw new Exception('Illegal file: ' . $file['name']);
                            break;
                        case 1:
                        case 2:
                            throw new Exception('File too large');
                            break;
                        case 3:
                            throw new Exception('File truncated');
                            break;
                        case 4:
                            // File slot is empty. Just skip it.
                            break;
                        default:
                            throw new EixMailMessageBadAttachmentException();
                            break;
                    }
                }
            }
        } else {
            throw new Exception('Unrecognised format');
        }
    }
875411
public function attachment($file, $name = null)
    {
        if (!is_null($name)) {
            $this->_attachments[] = ['name' => $key, 'file' => $value];
        } else {
            $this->_attachments[] = ['file' => $value];
        }

        return $this;
    }
820174
public function attachFile($file, $fileName = null)
    {
        if (gettype($file) == 'resource') {
            $this->file = ['fileName' => $fileName, 'fileContent' => $file];
        } else {
            $this->file = ['fileName' => $fileName, 'fileContent' => fopen($file, 'r')];
        }
    }
250248
public function download($filename, $alias = null)
    {
        $fileDowloader = new FileDownloader($this->headerBag);
        $fileDowloader->download($filename, $alias);

        // Terminate the script with success
        exit(1);
    }
780059
public function add($alias, $concrete = null)
    {
        $container = Container::getInstance();
        $container->add($alias, $concrete);
    }
83059
public function addEmbeddedFile(string $file, string $content = null, string $contentType = null): MimePart
    {
        return $this->inlines[$file] = $this->createAttachment($file, $content, $contentType, 'inline')
            ->setHeader('Content-ID', $this->getRandomId());
    }
924438
public function attach($file, $name = null, $type = null)
    {
        if (!$file instanceof MailAttachment) {
            $file = new MailAttachment($file);
        }

        if ($name) {
            $file->setFilename($name);
        }

        if ($type) {
            $file->setContentType($type);
        }

        $this->files[] = $file;

        return $this;
    }
1322661
private function addServiceAlias($alias, Alias $id, \DOMElement $parent)
    {
        $service = $this->document->createElement('service');
        $service->setAttribute('id', $alias);
        $service->setAttribute('alias', $id);
        if (!$id->isPrivate()) {
            $service->setAttribute('public', $id->isPublic() ? 'true' : 'false');
        }
        $parent->appendChild($service);
    }
1009485
public function add_attachment($message, $name =  "", $ctype =  "application/octet-stream", $encode =  "base64", $charset='', $contentid='') {
    $this->parts[] = array ( "ctype" => $ctype,
                             "message" => $message,
                             "encode" => $encode,
                             "name" => $name,
                             "charset" => $charset,
                             "contentid" => $contentid
                            );
  }
192844
public function addAttachment(
        $path,
        $name = '',
        $encoding = 'base64',
        $type = 'application/octet-stream',
        $disposition = 'attachment'
    ) {
        $this->_aAttachments[] = [$path, $name, $encoding, $type, $disposition];
        $result = false;

        try {
            $result = parent::addAttachment($path, $name, $encoding, $type, $disposition);
        } catch (Exception $exception) {
        }

        return $result;
    }
646404
public function attach_vcard($args)
    {
        if (preg_match('|^vcard://(.+)$|', $args['uri'], $m)) {
            list($cid, $source) = explode('-', $m[1]);

            $vcard  = $this->get_contact_vcard($source, $cid, $filename);
            $params = array(
                'filename' => $filename,
                'mimetype' => 'text/vcard',
            );

            if ($vcard) {
                $args['attachment'] = rcmail_save_attachment($vcard, null, $args['compose_id'], $params);
            }
        }

        return $args;
    }