PHP Detecting if source image url link leads to a “broken” image?

前端 未结 8 1592
迷失自我
迷失自我 2020-12-30 03:56

Suppose you have a thumbnail generator script that accepts source images in the form of a URL. Is there a way to detect if the source URL is \"broken\" - whether nonexistent

8条回答
  •  难免孤独
    2020-12-30 04:34

    onerror Event

    Execute a JavaScript if an error occurs when loading an image:

    The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image).

    Example:

    
    
    
    
    
    
    

    A function is triggered if an error occurs when loading the image. The function shows an alert box with a text. In this example we refer to an image that does not exist, therefore the onerror event occurs.

提交回复
热议问题