![]() |
'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 |
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, |
Thank you very much for this.
I think I can pull this one :) M:)rten |
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 Code:
<img src="<?php echo $date; ?>/img1.png"> Code:
function fcheck($name){ Code:
<img src="<?php echo fcheck("img1.png"); ?>"> Kind Regards Rob |
Quote:
Yes, it was part of what I was searching out knowledge for. Thank you! M:)rten:thumbsup |
Quote:
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 |
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"))); Quote:
Code:
<?php echo $info[0]." ".$info[2]." ".$info[1]; ?> $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 |
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 |
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'); Code:
<?php include("h.php")?> So basically I changed yours Code:
$date to $datetoday If I am trying to put the date-folders into a folder named 'gallery' Code:
<img src="gallery/<?php echo $datetoday; ?>/001.jpg"> 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 |
Hi Morten
To use the coding i provided then you want to use: Code:
<?php Rob |
Quote:
Very much. I'm nearly there now. M:)rten |
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