Shortest possible encoded string with decode possibility (shorten url) using only PHP

前端 未结 13 1807
甜味超标
甜味超标 2020-12-28 19:14

I\'m looking for a method that encodes an string to shortest possible length and lets it be decodable (pure PHP, no SQL). I have working sc

13条回答
  •  没有蜡笔的小新
    2020-12-28 19:53

    I think this would be better done by not obscuring at all. You could quite simply cache returned images and use a handler to provide them. This requires the image sizes to be hardcoded into the php script. When you get new sizes you can just delete everything in the cache as it is 'lazy loaded'.

    1. Get the image from the request
    This could be this: /thumbnail.php?image=img.jpg&album=myalbum. It could even be made to be anything using rewrite and have a URL like: /gallery/images/myalbum/img.jpg.

    2. Check to see if a temp version does not exist
    You can do this using is_file().

    3. Create it if it does not exist
    Use your current resizing logic to do it, but don't output the image. Save it to the temp location.

    4. Read the temp file contents to the stream
    Pretty much just output it.

    Here is an untested code example...

    
    

提交回复
热议问题