GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Webmaster Q & Fuckin' A (https://gfy.com/forumdisplay.php?f=27)
-   -   'o mighty php guru, take a look :) (https://gfy.com/showthread.php?t=1035466)

jollyhumper 08-24-2011 12:54 PM

'o mighty php guru, take a look :)
 
Hi

I know very little php by now, I understand code, but can't write yet.
<?php
include 'mypage.html';
?>
would include that html into my php page.
But let's say I need it a bit more advanced.

Pics sorted by dated folders [2011-08-24] [2011-08-25]

Is there a codesnippet that will get the files from correct folder?
A la <?php include '<dateoftoday>/filename.html' ?>

Or do I then in addition have a small script that actually checks the date to?

Cheers
M:)rten

crazyvipa 08-24-2011 02:41 PM

Something along those lines. You'll need to include a variable. How are you getting the DATE aspect? Is it today's date? Is it always going to be there?

In any case, I'll use today's date for an example.

<?php
$_today = date("Y-m-d");
include('./[' . $_today . ']/mysupercoolfile.html');
?>


By no means is the above code safe in any way. You should always add checks to see if files exist or php will fire off errors. Use php.net to find out functions and what they do, but is_file() is the function you'd want to use to make sure the file is actually there.

Remember that PHP runs in an environment, and usually based on absolute paths (on *nix systems) -- so you may have to use absolute directory structure.

Example: "./myw-ww.html" becomes "/var/www/superduper/httpdocs/myw-ww.html"


MOST hosting servers use mods that only allow you to access your home www directory, so the above example doesn't matter -- but not all.

Hope this helps,

jollyhumper 08-24-2011 10:21 PM

Thank you very much for this.
I think I can pull this one :)

M:)rten

robber 08-25-2011 11:56 AM

Hi Morten,

If I'm understanding your original post correctly, you have pictures sorted into files and you want to show specific pictures on specific days, is this going to be a whole site theme or only specific pictures which will change as you could almost set it up so each picture you want to include is checked otherwise you include a default image in its place (so you don't get broken images showing)

The top of you file would include some code like:
Code:

<?php
$date = date('Y-m-d');
if(!is_dir($date)){$date="default";}
?>

This would do a simple check to make sure the folder is there, this would be simple as long as you have a picture available for each one on the page which is linking so your picture tags on the page would be some thing like:

Code:

<img src="<?php echo $date; ?>/img1.png">
<img src="<?php echo $date; ?>/img2.png">
<img src="<?php echo $date; ?>/img3.png">

This would do the basics of what you need, but if you were wanting to be a bit more technical, you could add a second check to make sure the file exists, to make this simple it might be easier to write a little function, so under the header section add: (Make sure it is after the date check)
Code:

function fcheck($name){
if(file_exists($date."/".$name)){
return $date."/".$name;
}else{
return "default/".$name;
}}

Then all you would need to do to include the file is:

Code:

<img src="<?php echo fcheck("img1.png"); ?>">
<img src="<?php echo fcheck("img2.png"); ?>">
<img src="<?php echo fcheck("img3.png"); ?>">

Hope this helps, if you are unsure please ask

Kind Regards

Rob

jollyhumper 08-25-2011 12:30 PM

Quote:

Originally Posted by robber (Post 18380042)

Hope this helps, if you are unsure please ask

Kind Regards

Rob

Wow, thanks man. I am absolutely going to try this!

Yes, it was part of what I was searching out knowledge for.

Thank you!

M:)rten:thumbsup

jollyhumper 08-25-2011 01:56 PM

Quote:

Originally Posted by robber (Post 18380042)
Hope this helps, if you are unsure please ask

Rob


I did some experimenting and it sure did work.

But if I could add another question, I think I have all I need to complete the first project.
(But if this is to advanced, just forget it, I'll eventually get the knowledge as I work my way through "learn PHP" books.)

If Each folder had a text-file (or a XML-file) would it be difficult to pull out the info and put onto the picture-loaded page?

SOmething like this:

read xml and find attribute Name of Model, include it.
read XML and find attribute ShortText and include it.
Read XML and find attribute "BuyTheseGoodGFY-guys a beer", then do it!

Thx
M:)rten

robber 08-25-2011 03:47 PM

Morton,

It's simple enough to have it read the file, following on from what was in the previous example, you could get it to read through the information and then include the results so you could almost do: (under the current header info)

Code:

$info = explode(",",file_get_contents(fcheck("info.txt")));
This should read the file and every comma it will put this in a new value in an array, so if your file said:

Quote:

jollyhumper, beer alot, likes
to use the variables from here you just need to echo your array variables so, the following:

Code:

<?php echo $info[0]." ".$info[2]." ".$info[1]; ?>
Should produce: "jollyhumper likes beer alot" as the variables are set as:

$info[0] = "jollyhumper"
$info[1] = "beer alot"
$info[2] = "likes"

Hope this answers your question (this also uses the revert to default setting), just drop a blank file in with the name and it will mean no errors will come up.

Just one amendment to my original code needs doing, if you drop an @ infront of the file_exists so it reads @file_exists, it basically surpresses any error messages created by the function. (I forgot to add this originally)

If you have any questions about what this is doing and how you can expand it, please ask

Hope this answers your question

Rob

jollyhumper 08-25-2011 07:30 PM

Well, here is my experiment. Everything except the word "meet" is picked up from PHP commands :)

Hostinggallery.net


The ideas just comes streaming in :)

thanks!

M:)rten

jollyhumper 08-26-2011 05:10 AM

I',m using Zorgman's TEVS, quite happy with it.
I am trying to include this code in one of my tubes.

Now; Zorgman already have a
datecheck in the header.file; which is:
Code:

$datetoday = date('Y-m-d');
I just
Code:

<?php include("h.php")?>
attop of my galleryfile.

So basically I changed yours
Code:

$date to $datetoday
It does work like a charm, except for one thing.
If I am trying to put the date-folders into a folder named 'gallery'
Code:

<img src="gallery/<?php echo $datetoday; ?>/001.jpg">
The check routine always ends up with default, probably because the folder ain't on the root. But I can't fu:mad:ing find out how to alter your code to check for the date inside a gallery folder. What makes me fucking:mad: is just that the solution is right infront of me, I should've seen it! argh :)

SO, someone, a little more input would be appreciated.
The stuff is basically working at pornpitstop right now, in it's most basic form.

M:)rten

robber 08-26-2011 11:02 AM

Hi Morten

To use the coding i provided then you want to use:

Code:

<?php
$date = date('Y-m-d');
if(!is_dir($date)){$date="default";}
## Amend this to:
## if(!is_dir("gallery/".$date)){$date="default";}

function fcheck($name){
if(file_exists($date."/".$name)){
## Amend this one to:
## if(@file_exists("gallery/".$date."/".$name)){

return $date."/".$name; ## Amend this one to: return "gallery/".$date."/".$name
}else{
return "default/".$name; ## Amend this one to: return "gallery/".$date."/".$name
}}

?>

Hope this helps

Rob

jollyhumper 08-26-2011 11:24 AM

Quote:

Originally Posted by robber (Post 18382081)
Hope this helps
Rob


Very much. I'm nearly there now.

M:)rten

robber 08-26-2011 01:03 PM

You're welcome feel free to contact me if you want help outside of the board

Rob - ([email protected] <-- Replace the 0's with o's)


All times are GMT -7. The time now is 04:11 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc