Show a image to visitor and delete that image from the server (on same page load) [closed]

Asked
Active3 hr before
Viewed126 times

5 Answers

serverimage
90%

i just want to show a image to visitor in the same time delete this image from the server.,but when the page loads it deletes the file from server before it shows to visitor.,show the image. delete the record from database. delete the image from server using unlink().,So how i do this using ajax jquery. That is: load the page and show the image then execute the ajax code and delete the image.

<!DOCTYPE html>
<html>
<head>
    <script src="jquery.min.js"> </script>
</head>
<body>
<script>
    function unlinkImage(src) {
        $.ajax({
            type:"POST",
            url: "delete.php",
            data:{
                src:src
            }
        }).done(function() {
            alert('done')
        });
    }
</script>
<img src='someimage.png' onload="unlinkImage('someimage.png')" />
</body>
</html>

and to delete on php side (delete.php):

< ? php
$res = unlink($_REQUEST['src']); ?
>
load more v
88%

Lazy loading images that are not in the viewport improves initial page load performance and user experience. This is an in-depth guide to everything about lazy loading of images including native lazy loading methods.,Lazy loading is critical not only for good performance, but also to deliver a good user experience.,How can we solve such concerns around user experience with lazy loading of images?,lazy - Deferring the loading of assets till it reaches a certain distance from the viewport.

Thus, to lazyload such images, put the image URL in an attribute other than src. Let’s say we specify the image URL in the data-src attribute of the image tag. Now that src is empty, the browser doesn’t trigger the image load

<img data-src="https://ik.imagekit.io/demo/default-image.jpg" />
load more v
72%

When the use encounters an image, JavaScript moves the data-src value into src where it belongs,JavaScript watches the user scroll down the page,However, there is an exception to that rule: If an image’s src attribute is invalid, browsers will render its pseudo-elements. So, if we store the src for an image in data-src and the src is empty, then we can use a pseudo-element to set an aspect ratio:,That said, it does indeed introduce a noticeable problem: images not containing the src attribute (including when it’s empty or invalid) have no height. This means that they’re not the right size in the page layout until they’re lazy-loaded.

The image src provides a natural aspect ratio. Even when an image is resized responsively, its natural dimensions still apply. Here’s a pretty common bit of responsive image CSS:

img {
   max - width: 100 % ;
   height: auto;
}

However, there is an exception to that rule: If an image’s src attribute is invalid, browsers will render its pseudo-elements. So, if we store the src for an image in data-src and the src is empty, then we can use a pseudo-element to set an aspect ratio:

[data - src]::before {
   content: '';
   display: block;
   padding - top: 56.25 % ;
}

Another way we attempted to preserve the aspect ratio was to inline data URI for the src. as PNG. Using png-pixel.com will help with the lift of all that base64-encoding with any dimensions and colors. This can go straight into the image’s src attribute in the HTML:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAQAAAA3fa6RAAAADklEQVR42mNkAANGCAUAACMAA2w/AMgAAAAASUVORK5CYII=" data-src="//picsum.photos/900/600" alt="Lazy loading test image" />

First, I tried base64-encoding an SVG. Here’s an example of what that looked like in my HTML:

<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAzIDInPjwvc3ZnPg==" data-src="//picsum.photos/900/600" alt="Lazy loading test image">

In this case, instead of base64-encoding the SVGs, I used the “Optimized URL-encoded” technique from that post. Here’s the markup:

<img src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 3 2'%3E%3C/svg%3E" data-src="//picsum.photos/900/600" alt="Lazy loading test image" />

You don’t need to create a CSS block or generate a base64 string to get a perfect placeholder for images where the dimensions are unknown! For example, here’s a little React component that uses this technique:

const placeholderSrc = (width, height) => `data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}"%3E%3C/svg%3E`

const lazyImage = ({url, width, height, alt}) => {
  return (
    <img
      src={placeholderSrc(width, height)}
      data-src={url}
      alt={alt} />
  )
}

We’ve explored several techniques to prevent content reflow by preserving the aspect ratio of a lazy-loaded image before the swap happens. The best technique I was able to find is inlined and optimized URL-encoded SVG with image dimensions defined in the viewBox attribute. That can be scripted with a function like this:

const placeholderSrc = (width, height) => `data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}"%3E%3C/svg%3E`
load more v
65%

Rather than deeply nesting tables as in:,Make sure that any content that can be cached, is cached, and with appropriate expiration times.,Since each separate domain costs time in a DNS lookup, the page load time will grow along with the number of separate domains appearing in CSS link(s) and JavaScript and image src(es).,To mark an image for lazy loading, specify its loading attribute with a value of lazy. With this set, the image will only be loaded when it's needed.

Rather than deeply nesting tables as in:

<table>
   <table>
      <table>
         ...
      </table>
   </table>
</table>

use non-nested tables or divs as in

<table>...</table>
<table>...</table>
<table>...</table>
load more v
75%

Print (that is, display) the message on the web page.,In a nutshell, any computer program is a series of steps that are completed in a designated order. Say you want to display a welcome message using the web-page visitor’s name: “Welcome, Bob!” There are several things you’d need to do to accomplish this task:,Ask the visitor’s name.,If you try to preview this page in Internet Explorer and it doesn’t seem to do anything, you’ll need to click the “Enable blocked content” box that appears at the bottom of the page (see the Note on Note).

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/
html4/strict.dtd">
<html>

<head>
   <title>My Web Page</title>
   <script type="text/javascript">
   </script>
</head>
<!doctype html>
<html>

<head>
   <meta charset="UTF-8">
   <title>My Web Page</title>
   <script>
   </script>
</head>
<!doctype html>
<html>

<head>
   <meta charset="UTF-8">
   <title>My Web Page</title>
   <script>
      alert('hello world!');
   </script>
</head>
<!doctype html>
<html>

<head>
   <meta charset="UTF-8">
   <title>My Web Page</title>
   <script src="navigation.js"></script>
</head>
<script src="navigation.js"></script>
<script>
   alert('Hello world!');
</script>
<!doctype html>
<html>

<head>
   <meta charset="UTF-8">
   <title>My Web Page</title>
   <script src="navigation.js"></script>
   <script src="slideshow.js"></script>
   <script>
      alert('hello world!');
   </script>
</head>
load more v

Other "server-image" queries related to "Show a image to visitor and delete that image from the server (on same page load) [closed]"