src/whatsprot.class.php
protected function getMediaFile($filepath, $maxsizebytes = 5242880)
    {
        if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) {
            $this->mediaFileInfo = [];
            $this->mediaFileInfo['url'] = $filepath;

            $media = file_get_contents($filepath);
            $this->mediaFileInfo['filesize'] = strlen($media);

            if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                $this->mediaFileInfo['filepath'] = tempnam($this->dataFolder.Constants::MEDIA_FOLDER, 'WHA');
                file_put_contents($this->mediaFileInfo['filepath'], $media);
                $this->mediaFileInfo['filemimetype'] = get_mime($this->mediaFileInfo['filepath']);
                $this->mediaFileInfo['fileextension'] = getExtensionFromMime($this->mediaFileInfo['filemimetype']);

                return true;
            } else {
                return false;
            }
        } elseif (file_exists($filepath)) {
            //Local file
            $this->mediaFileInfo['filesize'] = filesize($filepath);
            if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                $this->mediaFileInfo['filepath'] = $filepath;
                $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION);
                $this->mediaFileInfo['filemimetype'] = get_mime($filepath);

                return true;
            } else {
                return false;
            }
        }

        return false;
    }
protected function getMediaFile($filepath, $maxsizebytes = 5242880)
    {
        if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) {
            $this->mediaFileInfo = [];
            $this->mediaFileInfo['url'] = $filepath;

            $media = file_get_contents($filepath);
            $this->mediaFileInfo['filesize'] = strlen($media);

            if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                $this->mediaFileInfo['filepath'] = tempnam($this->dataFolder.Constants::MEDIA_FOLDER, 'WHA');
                file_put_contents($this->mediaFileInfo['filepath'], $media);
                $this->mediaFileInfo['filemimetype'] = get_mime($this->mediaFileInfo['filepath']);
                $this->mediaFileInfo['fileextension'] = getExtensionFromMime($this->mediaFileInfo['filemimetype']);

                return true;
            } else {
                return false;
            }
        } elseif (file_exists($filepath)) {
            //Local file
            $this->mediaFileInfo['filesize'] = filesize($filepath);
            if ($this->mediaFileInfo['filesize'] < $maxsizebytes) {
                $this->mediaFileInfo['filepath'] = $filepath;
                $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION);
                $this->mediaFileInfo['filemimetype'] = get_mime($filepath);

                return true;
            } else {
                return false;
            }
        }

        return false;
    }
protected function getMediaFile ( $ filepath , $ maxsizebytes = 5242880 ) { if ( filter_var ( $ filepath , FILTER_VALIDATE_URL ) !== false ) { $ this -> mediaFileInfo = [ ] ; $ this -> mediaFileInfo [ 'url' ] = $ filepath ; $ media = file_get_contents ( $ filepath ) ; $ this -> mediaFileInfo [ 'filesize' ] = strlen ( $ media ) ; if ( $ this -> mediaFileInfo [ 'filesize' ] < $ maxsizebytes ) { $ this -> mediaFileInfo [ 'filepath' ] = tempnam ( $ this -> dataFolder . Constants :: MEDIA_FOLDER , 'WHA' ) ; file_put_contents ( $ this -> mediaFileInfo [ 'filepath' ] , $ media ) ; $ this -> mediaFileInfo [ 'filemimetype' ] = get_mime ( $ this -> mediaFileInfo [ 'filepath' ] ) ; $ this -> mediaFileInfo [ 'fileextension' ] = getExtensionFromMime ( $ this -> mediaFileInfo [ 'filemimetype' ] ) ; return true ; } else { return false ; } } elseif ( file_exists ( $ filepath ) ) { //Local file $ this -> mediaFileInfo [ 'filesize' ] = filesize ( $ filepath ) ; if ( $ this -> mediaFileInfo [ 'filesize' ] < $ maxsizebytes ) { $ this -> mediaFileInfo [ 'filepath' ] = $ filepath ; $ this -> mediaFileInfo [ 'fileextension' ] = pathinfo ( $ filepath , PATHINFO_EXTENSION ) ; $ this -> mediaFileInfo [ 'filemimetype' ] = get_mime ( $ filepath ) ; return true ; } else { return false ; } } return false ; }
Retrieves media file and info from either a URL or localpath.

@param string $filepath     The URL or path to the mediafile you wish to send
@param int    $maxsizebytes The maximum size in bytes the media file can be. Default 5MB

@return bool false if file information can not be obtained.
Retrieves media file and info from either a URL or localpath .