![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,119
|
![]() 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.
__________________
NOTHING TO SEE HERE |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Industry Role:
Join Date: Apr 2013
Posts: 373
|
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 ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
making it rain
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,006
|
placeholder.jpg as the 404 page in your images directory?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
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. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
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). |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Jul 2003
Location: Australia
Posts: 5,065
|
__________________
Traffic.Tools - 40+ Free Tools Free.Marketing - 150+ Free Tools Submission.Tools - 20+ Free Tools |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Too lazy to set a custom title
Industry Role:
Join Date: Sep 2005
Location: Canada
Posts: 10,200
|
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 | |
Confirmed User
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,119
|
Quote:
![]() 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 ![]()
__________________
NOTHING TO SEE HERE |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Industry Role:
Join Date: Sep 2013
Location: The Netherlands
Posts: 805
|
Quote:
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Making PHP work
Industry Role:
Join Date: Nov 2002
Location: 🌎🌅🌈🌇
Posts: 20,227
|
I don't know if there is much benefit for it but :
PHP Code:
![]()
__________________
Make Money with Porn |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Confirmed User
Industry Role:
Join Date: Jan 2003
Location: Nomad Land
Posts: 1,602
|
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.
__________________
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() ![]() |
|||||||
|
|||||||
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 |