Forum Moderators: coopster
Say the file i want to link is called portfolio.php and is in the folder (from site root) images/portfolio/.
I want to link this file to a file called main.php.
But not how you may think...
I have tried require and include, but they write the file into the file its required or included into! I dont want this as the script in portfolio.php can only work in images/protfolio folder.
So is there any way to link it into main.php. Like in HTML you would use an iframe, but I dont wanna use that!
Is there any other way?
There are many strategies you could try, but somehow you've got to rewrite all those links so they work from the current directory. A long time ago I wrote a function that does that, by counting the slashes in the URI to get the current depth, splitting on the "/" and popping off directories negated by "../"
and I've been using it ever since.
You could try a fancy replacement script that searches your HTML tags for attributes:
href,src,background
and religns the "depth" of all the attributes for the current page.
If you get totally stuck, I can sticky you the function I mentioned, but honestly it's clunky and awkward. I'd like to see what other people suggest.
the script, portfolio.php, is a gallery script that uses the command 'getcwd();'
the script lists the folders in the folder portfolio (as they have images in them).
below is the portfolio script:
- starts -
<?php
// snapshot gallery
$cwd = getcwd(); // get current working directory
// create snapshot sub navigation
// search current working directory for snapshot folders
$handle = opendir("$cwd");
$folders = array();
$i = 0;
while (($directory = readdir($handle))!= false) {
// read snapshot folders.
if (
(is_dir($directory)) and // make sure $directory is a folder, not a file
($directory!= ".") and // don't read hidden folders
($directory!= "..")
) {
$folders[$i] = "$directory"; // add folder name to array
$i++;
}
}
sort($folders); // sort folder names alphabetically
reset($folders); //set array to read from the start after sorting
// create links with folder names. Format into list.
$snap_sub_nav = "
<div id=\"snapshot-nav\" style=\"text-transform: capitalize;\" align=\"left\">
<p>Click below to view examples of our work »</p>
";
foreach($folders as $value) {
$snap_sub_nav .= "›
<a href=\"index.php?dir=".urlencode("$value")."\" title=\"View Gallery\">$value</a><br>
";
}
$snap_sub_nav .= "
</div>
";
// end snapshot sub navigation
<chopped out large chunk of code>
// determine page display
if (($dir!= "") and ($pic!="")) { //display image with links
echo "<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=225 align=left valign=top style=padding:5px;>"; //start of table
echo $blurb;
echo "<p>Quick Links »</p>";
require ("http://example.co.uk/quicklinks.php");
echo "</td><td align=right valign=top>"; //end of blurb td
echo $image;
echo "</td></tr></table>"; //end of table
} else if
.... chopped more
}
?>
- ends -
You can ignore all the crap after the first few lines!
Because the require and include functions write the files into the parent file, this script cant work coz the parent file, navi.php, isnt in the portfolio folder!
Is there any other way to specify the cwd?
Aswell as that, you can see that ive used:
require ("http://example.co.uk/quicklinks.php");
is there any way that this can be linked relitavly (eg, ../) because I couldnt get it to work!
Thanks!
[edited by: jatar_k at 4:12 pm (utc) on July 23, 2004]