Found some 404s for image files in statistis - php

I am running a website in which I generate dynamic images for users. Initially, I was saving all the images generated forever so that I can use those images when required to be shown again but since recently I started getting some decent traffic, so I thought instead of saving and reusing the images I should generate them again when they need to be shown again.
Now what I am doing is: I have created a temp folder and I save every image in that temp folder and show it to user. And when this image is required to be shown again, I just re-create that image instead of using this temp image. And temp folder is now emptied at sometime daily.
But now I have started getting 404s in my error logs for the images. I am not getting that from where I am getting those 404s since I myself tried deleting image from tmp and then revisited that page. The image was re-created and was shown properly. I am badly stuck at this. One thing I would like you to tell is that I am allowing user to share those result-pages(with images) on social networks.
So it is like:
I create one image in tmp and show it on some result.php page. I
also put the image's link in og meta tag so that it can be properly
identified by social networks while sharing.
If somebody visits result.php page again, then it shows image again. However, if image is not available(i.e. deleted as daily
job), then it recreates it first, saves at that location and then
shows the page.
I am getting 404s for .jpg image files in error log.
On debugging it more, I found that these 404s are there because of access to images from Facebook IPs. The IPs from which 404s are detected are like: 66.220.158.119, 173.252.101.116, etc. On some googling, I founf that these IPs are allocated to Facebook.
So it means: facebook bot is accessing the images because these links were earlier shared on facebook via facebook share. Can someone please tell me is there any harm if later(say after 1 day of sharing), if facebook does not find the image anymore on my server? Will it not show anymore on shared link on facebook also?

Related

Redirect direct image urls to image post or attachment page?

New :
I have a wallpaper website and I recently checked the server log of the files accessed and I saw that I am getting lots of traffic on the image files rather than the page of the website.
So I want to do is redirect example.com/sample-image.jpg to example.com/sample-image.html
I am using WordPress CMS and I tried one .htaccess code but it redirects all the images to the homepage of website :(
OLD:
When a user attempts to load an image directly into the browser (for example from Google Images), the browser normally opens just the bare image.
I'm trying to address the following situation:
1) User is browsing Google Images and finds an image. 2) Google Images offers the user to open the website where the image was found or just open the original image. 3) The user chooses the latter, therefore the ball is now on the webserver where the image is hosted. 4) htaccess detects a human operated browser trying to access directly to an image in /uploads/ folder. 5) htaccess redirects the user to single-attachment.php or post in which image include or attached.
Images/media it is post type. Try get_permalink($id_of_attachment); If you have url of image you can get id too. Example by get_post_thumbnail_id();

Secure files and display them as well

My question is about HTML and PHP.
This is my setup right now:
A website where user have accounts
A FTP server with pictures (currently none)
Files are currently saved on the website in the "PICTURES" folder (which is accessible by everybody who know the full URL)
So, I would like to know how I can display the images without storing them on the website (which will fix my URL problem).
My idea was to move the files on the FTP server, and when a users logon and request a page with those images, download them through a FTP connection, save them on the website, display the images, and remove them. Which would make them accessible only between the downloading time. But this solutions sounds REALLY bad to me.
You need always to have a place where your images are stored. But, if you don't want to give a user the chance to know where are stored, you can create a system which is used to show the images.
Think about this, if you want to download a file from Mega, you can't access to the URL where the file is stored, instead of that, the server itselfs calls a system who assign you a "key" and you can download the file only through that system using your "key".
You could use a system like "base64" so you can encode your image, and show it using it, or, you can use the "header" modifier so, you can display an image using a PHP code.
For example your image tag will be like:
<img src="processImage.php?id=01&user=10&key=123" />
So, your processImage will return a "tricky" image, actually not the image, but the code processed by PHP will be returned, like using "imagejpg()" function with the header "Content-Type:image/jpeg" and then the user will not know where the image is stored actually but the img will works actually.

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.

Image isn't refreshed on application

I'm working on a PHP application to store some personal information (including photo). I'm storing the image on a specific folder (let's say myapp/images/people/).
After saving a photo my app is redirected to a page showing the information of the specific person (kind of a profile).
If the photo is saved for the first time (no other photo was previously saved for that person) then the photo is shown in the profile. Everything seems to work at this point.
The problem is when I want to change the photo. When I replace a photo my applications keeps showing the old one. I've checked the server and the old photo is gone, there's only the new one (as I need) but the application doesn't show it.
I guess it's something to do with cache.
I've tried by adding the html tag with no cache values, I've tried by adding the same values by using the header() PHP function but nothing.
I also tried by using:
if(file_exists($imagepath))
{
unlink($imagepath);
}
and similar I've used
if(file_exists($imagepath))
{
unlink($imagepath);
clearstatcache();
}
but also nothing.
Can someone help me with this? Any idea about what's going on? The new photo is in the server, the old one is not but the app keeps showing the previous file.
The image is cached in the browser. The best way is to generate a new image name on the server and return the new image in the HTML. Since it is a new image for the browser, it won't get it from the cache and you will see the new image in the application.

How do I show a link once a file is uploaded

I had trouble finding an answer for this problem. I would like to display a link to a page that has a video file on it but I don't want the link to appear until after the video file is uploaded.
It's a site where users upload videos so I don't want to have to manually put the links there for them after they upload their videos, nor do I want to make the links ahead of time since users will click them and there will be no video available.
So, is there a way to keep a link hidden until a file is uploaded. Once the file is uploaded the php page where the link will be on checks to see if it exists and then if it does the link is shown, otherwise the link stays hidden.
Each time the form that the client uses to upload a file is sent store the information of the file in a database.
Each time the client request the list of videos, query the database and build the web page based on the results.
Make sure to associate the uploaded files to the users, so you don't mix the up. Are you managing authentication already?
If you want to have the links appear as soon as the upload is finished without reloading the page, then you need ajax.

Categories