View Single Post
Old 05-02-2022, 10:49 AM  
blackmonsters
Making PHP work
 
blackmonsters's Avatar
 
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,230
I don't know if there is much benefit for it but :

PHP Code:
<?php

    $placeholder_path 
__DIR__ "/placeholder.jpg";

    
$myPage explode('.',strtolower($_SERVER[REQUEST_URI]));
    
$myImage trim(preg_replace("/[^a-zA-Z0-9\-]+/"""$myPage[0]));
    
$alt $myImage;
    
$myImage $myImage '.jpg';

    
$new_path __DIR__ "/$myImage";
    
    if (@
getimagesize($new_path )) {
            echo 
"<img src='$myImage'>";
    } else {

        
$placeholder_image = @file_get_contents($placeholder_path);
        
        
$file fopen("$new_path","w+");
        if (
flock($file,LOCK_EX)) {
            
fwrite($file,$placeholder_image);
              
fflush($file);

              
flock($file,LOCK_UN);
        } else {
              echo 
"Error locking file!";
        }
        
fclose($file);    
        
        echo 
"<img src=\"$myImage\" alt=\"$alt\">";

    }

?>

__________________
Make Money with Porn
blackmonsters is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote