Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-01-2022, 04:00 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 709
Is this possible to do using php?

I have a bunch of web pages that all contain an image on them however, not all of the pages *actually* have an image associated with them so I'm using a generic placeholder.jpg image.

Is there a method I can use to change the name of that image dynamically so depending on what the pages title is, it will rename itself automagically?

For example:

The page catfood.php would display the generic placeholder.jpg but it would be renamed to catfood.jpg?

Anyone know of a simple/easy method of achieving this please?

TIA.
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-01-2022, 04:48 PM   #2
Webster01
Confirmed User
 
Webster01's Avatar
 
Industry Role:
Join Date: Apr 2013
Posts: 363
I had that done as a custom mod by Nick from RoboScripts on his PHP script, for custom posts on the site.
But also had that done by another dev on a WP project.
It renames the image according the post title/permalink.
So when the link is /sexy-hot-girl it renames the image to sexy-hot-girl.jpg

Sure that is possible and a great mod!
But I´m not too technical so I cannot tell you exactly how

Also you maybe want to get an alt tag added automatically?
And the title + alt tag on the thumbs in the thumb overview??
Another great idea
Webster01 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-01-2022, 05:05 PM   #3
fuzebox
making it rain
 
fuzebox's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 21,817
placeholder.jpg as the 404 page in your images directory?
fuzebox is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-01-2022, 07:44 PM   #4
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
yourdomain.com/go-fuck-yourself.html will become go-fuck-yourself.jpg.

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

// can also be: $myImage = 'files/images/' . $myImage . '.jpg';
// or whatever folder or image file format you want...

if (@getimagesize($myImage)) {
echo "<img src='$myImage'>";
} else {
// file doesn't exist, show placeholder
echo "<img src='files/images/placeholder.jpg'>";
}
die();
?>


I got a feeling there's even a faster way, but just like you, I'm too lazy to dive into the PHP docs as well.
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-01-2022, 07:54 PM   #5
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Oops, didn't read it properly. I see what you are trying to achieve.

That would probably be more a case for url rewriting rules in your htaccess file in combination with a few lines of PHP on that page.

Thing is, you don't want to screw this up and might want to think of what logic to apply on how to handle security and validation, considering it is user input (anyone can make up and type in some random page url).
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 03:10 AM   #6
lock
Confirmed User
 
lock's Avatar
 
Industry Role:
Join Date: Jul 2003
Location: Australia
Posts: 5,065
https://stackoverflow.com/questions/...d-image-in-php
__________________
Traffic.Tools - 40+ Free Tools
Free.Marketing - 150+ Free Tools
Submission.Tools
- 20+ Free Tools
lock is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 04:36 AM   #7
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
I think OP is looking to rewrite urls, rather than creating a ton of copies of the same image file.
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 06:20 AM   #8
NoWhErE
Confirmed User
 
NoWhErE's Avatar
 
Industry Role:
Join Date: Sep 2005
Location: Canada
Posts: 9,691
Technically you can do it. The main problem is re-writing the image filename every time.

This means you need to copy the placeholder.jpg to a new file, rename it, then display it.

And then you need to have a clean-up script that deletes the new .jpg after the session is finished (or have it clean up your images directory every X hours or so).


HOWEVER, is it worth doing? Probably not.
The images won't be indexed by google images because they will only exist for a finite amount of time (unless you want to keep all of the clones in a directory which could result in tens of thousands of images AND this also opens up your site to spam attacks that would overload your server storage).

As for SEO benefits, the return on investment is negligible to none.



So if you would actually want to do it the process would roughly look like this:

1 - Get the URL slug (mydomain.com/this-is-the-slug) : How you do this varies on your setup. In Wordpress $post->slug, in pure PHP you'd need to use some REGEX
2 - Find the placeholder.jpg image: $imagePath = /home/domain/public_html/images/your-image.jpg
3 - Copy the file with its new name : $copied = copy($imagePath , $newName);
4 - Serve the image to the user: $image = $copied ? $copied : $default_placeholder;
__________________
skype: lordofthecameltoe
NoWhErE is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 07:36 AM   #9
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana.
Posts: 709
Quote:
Originally Posted by NoWhErE View Post
Technically you can do it. The main problem is re-writing the image filename every time.

This means you need to copy the placeholder.jpg to a new file, rename it, then display it.

And then you need to have a clean-up script that deletes the new .jpg after the session is finished (or have it clean up your images directory every X hours or so).


HOWEVER, is it worth doing? Probably not.
The images won't be indexed by google images because they will only exist for a finite amount of time (unless you want to keep all of the clones in a directory which could result in tens of thousands of images AND this also opens up your site to spam attacks that would overload your server storage).

As for SEO benefits, the return on investment is negligible to none.



So if you would actually want to do it the process would roughly look like this:

1 - Get the URL slug (mydomain.com/this-is-the-slug) : How you do this varies on your setup. In Wordpress $post->slug, in pure PHP you'd need to use some REGEX
2 - Find the placeholder.jpg image: $imagePath = /home/domain/public_html/images/your-image.jpg
3 - Copy the file with its new name : $copied = copy($imagePath , $newName);
4 - Serve the image to the user: $image = $copied ? $copied : $default_placeholder;
Thanks for that detailed response

Also, thanks for everyone else who replied, it seems like it might just be worth placing a standard call to the default image after reading the responses and the explanation on how SEO benefits will be negligable, again appreciate the replies
__________________
DMCASUITE
BETA Testers Needed.
Publisher Bucks is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 09:00 AM   #10
zijlstravideo
Confirmed User
 
zijlstravideo's Avatar
 
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
Quote:
Originally Posted by NoWhErE View Post
Technically you can do it. The main problem is re-writing the image filename every time.

This means you need to copy the placeholder.jpg to a new file, rename it, then display it.
Making a copy of the same image file doesn't make much sense...

Instead, I would create a php file, let's say, call it placeholder.php.

- Add rewrite rule to .htaccess file:
RewriteRule image-(.*)\.jpg$ placeholder.php?slug=$1 [L]

- Create placeholder.php:
Takes input from a query like this: placeholder.php?slug=this-is-the-url-slug.
Then, check if that url slug is a match with an entry from the SQL database.
If it's a match, print the new re-written image url (<img src='image-this-is-the-url-slug.jpg'>) else, just print (<img src='image-fallback.jpg'>).

Replace the - with spaces and you can include it as an alt tag as well.
__________________
Contact: email
zijlstravideo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 10:49 AM   #11
blackmonsters
Making PHP work
 
blackmonsters's Avatar
 
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,135
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\">";

    }

?>

__________________
You mad as fuck because you suck.
You have no life.

blackmonsters is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-02-2022, 07:48 PM   #12
natkejs
Confirmed User
 
Industry Role:
Join Date: Jan 2003
Location: Nomad Land
Posts: 1,571
I think the easiest and fastest solution would be an internal URL rewrite.

domain.com/placeholder/<whatever>.jpg
to
domain.com/placeholder.jpg

RewriteEngine on
RewriteRule "^/placeholder/.+\.jpg$" "/placeholder.jpg" [PT]

Then you would just echo the page slug as the image name.

ie:
domain.com/placeholder/my-whatever-slug.jpg

Whether it's well invested time to set that up is for you to decide however ;)

Edit:
Just realized Directory and FallbackResource would be a better solution if talking Apache. Works out almost the same except your existing images and "dynamic placeholders" would exist in the same directory. Like the 404 solution suggested above but without 404 response codes.
__________________
natkejs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
image, pages, generic, method, placeholder.jpg, page, catfood.php, automagically, catfood.jpg, rename, tia, simple/easy, display, achieving, renamed, web, bunch, php, dynamically, depending, change, title



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.