/** * Reads an file from the given url and stores it on disk. */ public function saveFromUrl($url) { $response = Media_Uploader::saveFromUrl($url, 'file'); if (!$response) { $this->_error = Media_Uploader::getError(); } else { $this->_id = $response; } return $this; }
/** * Gets a new, unused filename for the given filename and returns it with * the full path to the new filename. * * @param string $filename The original filename, no paths. * * @return An array, first element is the new filename, the second is the full path. */ private static function _getNewNameAndPath($filename) { if (!($filesPath = Media::getFilesPath())) { self::$_error = 'Files directory doesn\'t exist or isn\'t writable.'; return false; } if (!($mediaPath = Media::getMediaPath())) { self::$_error = 'Media directory doesn\'t exist or isn\'t writable.'; return false; } $uploadPath = $filesPath . $mediaPath; $newFilename = self::_getAvailFilename($filename, $uploadPath); $fullPath = ROOT . $uploadPath . $newFilename; return array($newFilename, $fullPath); }