clearvision Posted February 10, 2021 Posted February 10, 2021 Over the years I've had a CMS(Pages) block that generates a JPG of last 40 avatars posting to site. I've used a PHP block that regenerates based on the age of the saved temporary file as it involves a lot of fetching of avatar files each time it runs. Originally I could also have set the cache time of the block really long and just rerun, but no longer... The file was generated using PHP GD as imagejpeg($destimg,filepath); All this on hosted services. Years ago there was access to the directory structure and I just picked a place for the temp file. Then I had to change to using a file in "uploads" directory as hosted no longer had access to the directories. Recently this too has broken I suspect because of hosting's move to s3 storage for files. So.... Anyone know how I can write and read a temporary file on the current version of software (hosted) from a Pages PHP block ? Thanks
bfarber Posted February 10, 2021 Posted February 10, 2021 You would need to use the framework methods for storing and retrieving files. $file = \IPS\File::create( "core_Theme", $filename, $fileData ); print $file->url; /** * Create File * * @param string $storageExtension Storage extension * @param string $filename Filename * @param string|null $data Data (set to null if you intend to use $filePath) * @param string|null $container Key to identify container for storage * @param boolean $isSafe This file is safe and doesn't require security checking * @param string|null $filePath Path to existing file on disk - Filesystem can move file without loading all of the contents into memory if this method is used * @param bool $obscure Controls if an md5 hash should be added to the filename * @return \IPS\File * @throws \DomainException * @throws \RuntimeException */ public static function create( $storageExtension, $filename, $data=NULL, $container=NULL, $isSafe=FALSE, $filePath=NULL, $obscure=TRUE ) clearvision 1
Recommended Posts