PHP Image Cache - php

I have a mini gallery I created and what I did was just used FTP, no database so when I upload a photo it is named "image1.jpg" and then if I upload another image it is named "image2.jpg" and so on. Well, if I delete image1, then image2 is automatically renamed to image1.jpg and all of them get re-named if there are more.
The problem is that now the new image1 is showing the old image unless I clear my cache. I found a mini solution to work around this:
$rand = rand(100,1000);
<img src="images/image1.jpg?<?=$rand;?>">
That works fine but I found that it does not work with facebox, whenever I try to view the full-size image in Facebox, it can't read the URL with the random number and it just brings up a ton of characters that usually crashes my browser.
Is there a better way to fix this?

You can put no cache headers on the image directory.

Related

Preview page Image orientation

I picked up some work updating images on a website that someone else had created managed previously.
I determined how it was laid out enough to get what needed to be done done.
However, two images I added are showing in landscape orientation on the preview page but when the image is clicked on it shows properly in the portrait orientation.
www.artbyheenan.com/art.php
Its the first two images, if anyone can take a look and give me some input I'd appreciate it.
Initially I thought it may have been the image size as it was rather large and I resized it to 200kb but still the same.
It has to do with the images meta/exif data and a known issue in the browsers.
- https://github.com/GoogleChromeLabs/squoosh/issues/299
- Chrome Image EXIF Orienation Issue
The best solution right now is to re-save the image in photoshop or something similar.
The problem is that your images have EXIF data that has rotation set to 90ยบ CCW.
If you delete the EXIF data, they will display properly.
You can do that here: Remove EXIF data online

Image does not update (PHP)

I'm currently working on a system right now that involves the use of many images. There are some images (specially background images) that I used where when I updated the images that includes the picture path, the image does not update. I checked the path if it's correct and even the folder containing the picture.
However, I noticed that when I clear the history of the picture, that is the time the picture becomes accurate. I did not use any session or cookie for saving my image. Is there an explanation for this?
Add some parameter to image link and change this parameter after image update ;)
Example :
src="image.png?timestamp=20180602" ;

Webcam image stream for website implementation

Setting up a live image stream on a website, using images from a webcam. Trying to work out the implementation of it. The webcam takes a picture and requires a crop, resize and upload (not necessarily in that order), before it is displayed to the user, with a new image every minute. Currently I have a php script that does the cropping and resizing, while a webcam program automates the picture taking and uploading. However...
Uploading directly over the existing image causes an issue if the user reloads the page while the upload is taking place, resulting in a missing image.
Uploading with a different filename, then renaming it causes an issue if the user reloads the page during the renaming, resulting in a combination of both images.
Using a sequential filename system then gets tricky with the webpage requiring to know the new upcoming file every minute, along with a potential backlog of images.
Any suggestions are appreciated. Hopefully I'm missing something simple.
Thanks.
Just upload your image with different name, set the current image name somewhere, either in config file or MySQL, and after upload change it.

Can I un-cache one image? Or should I do things differently?

I allow users to add a profile picture of themselves to an account, pretty standard stuff.
To make things simple, when they update their image I simply overwrite the image they currently have stored (its not a big part of what we do so simple approach)
So, page is shown with their current image, they can then choose to upload a new one, the uploaded file is then saved, image URL updated in MySQL table and page is displayed again.
The image is uploaded correctly, MySQL table updated correctly, but the image is cached so old image shows on page even though they have uploaded a new one.
Can I un cache one image? Is there a better way to do this?
For avoiding image caching you can simply add a query sting in the image src. Best would be adding a date time.
{$t = getDate();}
and in your image src add: src= "path.jpg?t=".$t
For this you need not to change anything for new image..Date time automatically gets changed every second ;)
Hope it helps..
Use versioning. In the link for the image, instead of abc.jpg say abc.jpg?v=5. And when a new image is uploaded, change the number.
see this question

ckeditor, php, image display issue

I have a download.php file to display images on a web page as well as downloading files like pdfs, docs, etc.
in ckeditor if the src for the image is /download.php it dispalys like there is no image or broken link image, if the src for the image is http://www.mydomain.com/download.php my image displays just fine in ckeditor.
Any thoughts? And no i cant just make it put the full domain. There is a reason to long, complicated, and stupid to explain thanks to the web hosting company.
In the configuration you need to set the baseHref to the full path, then it will add that to the images/files you upload and insert.

Categories