real_illusions Posted December 4, 2006 Share Posted December 4, 2006 Hi,How do you link to the next file and/or folder in that particular folder.In particular, its my gallery script i got on my websitehttp://winged.info/ is the original files and scripthttp://www.surrealillusions.co.uk/galleries/ is where mine is. (yes i know about the link to the winged site overlapping, i need to sort it out).Since the files and folders change everytime the page changes, i cant put in a direct link to the next file and folder.So...i'm a bit stumped... Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2006 Share Posted December 5, 2006 You need to get a list of the files and folders, figure out where you are in that list, and then you can give a link to the previous and next items. If your page receives the filename through the URL, then you can load the folder that contains that file, find the file by comparing names, and get the next/previous. Link to comment Share on other sites More sharing options...
real_illusions Posted December 5, 2006 Author Share Posted December 5, 2006 i think i get youwould i need some sort of if/else statements??if the url is in the main folder view, i.e the index, then no next/prev links.if the url is in a subfolder, then next/prev folder linksand if the url is in picture view mode, then next/prev image links.is that what i need? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2006 Share Posted December 5, 2006 Pretty much. The key is just to find out where you are, and then you can give a link to what is before and what is after. Link to comment Share on other sites More sharing options...
real_illusions Posted December 5, 2006 Author Share Posted December 5, 2006 is this anywhere near been close? (i say with due sense of dread and fear of been mocked from the php community ) <?php$url=index.php("");if ($url=="index.php?file=/$dir") echo "<a href="\index.php?file=/$dir\">Prev directory</a><a href="\index.php?file=/$dir\">Next directory</a>"; elseif ($url=="index.php?file=/$dir/$file")echo "<a href="\index.php?file=/$dir/$file\">Prev file</a><a href="\index.php?file=/$dir/$file\">Next file</a>"; else echo "Â "; ?> Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2006 Share Posted December 5, 2006 Uh.. at the risk of damaging your ego, I guess that is a little close. I mean, at least it's the right language.First, there's this:$url=index.php("");That's bizarre! Syntactically speaking, this is what the PHP engine thinks when it sees that:You are assigning a value to the variable $url. The value to be assigned (the right side of the equals) is a function call, because of the parentheses. It's thinking it would be one of two things (I'm not sure which). Either there is a constant called index (since it does not have a $ in front, it assumes a constant), and you are concatenating the value of the "index" constant with a constant called php. Since the dot is the string concatenation operator, this:index.phpis the constant "index" combined with the constant "php". Since there are no constants called either "index" or "php", I'm not sure what it will do, it may just use the literal strings "index" and "php". Anyway, the result of whatever that is, since you have the ("") after, it assumes that there is a function. So if it concatenates the strings "index" and "php", it will try to run a function called indexphp. And then assign the value of whatever that function returns to the $url variable.So, I'm not sure what you're trying to do with that line, but it's definately not doing what you are expecting.Basically, what I was thinking was that you need to have the file or folder you are looking at in the URL. So, if the URL of the page is this:index.php?f=/dir1/dir2/file.extThen you get the value of f like this:$f = $_GET['f'];You will need to use a function like dirname to get the directory where you are at, and then you can use a function like scandir to get a list of the files in that directory. Or, if you don't have PHP5, you would need to use a combination of opendir and readdir to get a list of the files. Once you have a list of the files, you scan through the list until you find the file in the $f variable. Once you find that file, then the next file in the list is the file that goes in the URL of the "next" link, and the previous file in the list is the one that goes in the URL of the "previous" link. Link to comment Share on other sites More sharing options...
real_illusions Posted December 5, 2006 Author Share Posted December 5, 2006 Uh.. at the risk of damaging your ego, I guess that is a little close. I mean, at least it's the right language.hehe..at least i got something right :)i dont know what i'm doing with the first line either, dont worry :)can you give me a guide on what i'm supposed to be doing? Link to comment Share on other sites More sharing options...
justsomeguy Posted December 5, 2006 Share Posted December 5, 2006 The description I gave at the end of my last post is pretty much it, you can use the dirname and basename functions to get the directory path and the filename of the current file, and from there you can use the directory functions to get a list of the files in the directory and find the one you are on now. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 3, 2007 Share Posted January 3, 2007 In response to your PM, try this. I didn't test it, but hopefully it will work. Change the variable on the top to the base folder holding your files. <?php$base_folder = "c:\\path\\to\\base\\";$url = $_GET['f'];$fname = $base_folder . $url;$dirname = dirname($fname); #folder name$filename = basename($fname); #file name$prev = $next = $cur = "";$dir = opendir($dirname);$done = false;while (!$done){ if (false === ($file = readdir($dir))) { $done = true; } else { if ($file != "." && $file != "..") #leave out . and .. { if (!is_dir($file)) #exclude directories, files only { if ($file == $filename) #if we found the selected file { $prev = $cur; if (false !== ($file = readdir($dir))) #get the next file $next = $file; $done = true; } else { $cur = $file; } } } }}closedir($dir);if ($prev != ""){ echo "<a href=\"index.php?f=" . urlencode(str_replace($filename, $prev, $url)) . "\">Previous file</a>";}if ($next != ""){ echo "<a href=\"index.php?f=" . urlencode(str_replace($filename, $next, $url)) . "\">Next file</a>";}?> Link to comment Share on other sites More sharing options...
real_illusions Posted January 3, 2007 Author Share Posted January 3, 2007 thanks alotmuch appreciatedI'll see how it works, and get back to you:) Link to comment Share on other sites More sharing options...
real_illusions Posted January 5, 2007 Author Share Posted January 5, 2007 didn't seem to work.i either get nothing at all, or the following errorWarning: opendir(http://www.surrealillusions.co.uk/galleries) [function.opendir]: failed to open dir: not implemented in /galleries/index.php on line 134Warning: readdir(): supplied argument is not a valid Directory resource in /galleries/index.php on line 138Warning: closedir(): supplied argument is not a valid Directory resource in /galleries/index.php on line 165or something like that anyway.i've tried the script in various files, where i think it should go, but nothing worked. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 8, 2007 Share Posted January 8, 2007 You cannot use an HTTP path, the path must be the local filesystem path. Opendir does not work with remote directories, it needs local access. Link to comment Share on other sites More sharing options...
real_illusions Posted January 8, 2007 Author Share Posted January 8, 2007 ok..now i get a different errorWarning: opendir() [function.opendir]: open_basedir restriction in effect. File(/) is not within the allowed path(s): (path removed)Warning: opendir(/) [function.opendir]: failed to open dir: Operation not permitted in nextprevscript.php on line 14Warning: readdir(): supplied argument is not a valid Directory resource in nextprevscript.php on line 18Warning: closedir(): supplied argument is not a valid Directory resource in nextprevscript.php on line 45I've set up a test bit, where some images are in a subfolder. If i put the path as "/images/" , it comes up with that error...i type anything else, and nothing appears. Link to comment Share on other sites More sharing options...
justsomeguy Posted January 8, 2007 Share Posted January 8, 2007 Here's a description of the open_basedir restriction:http://www.supanames.com/support/open_basedir.htmlThe path "/images/" is referring to a folder called images in the root of the filesystem. Since it starts with a slash, it is looking in the root. And, the server has restricted access to the root folder using the open_basedir restriction. Either remove the beginning slash, so it knows the path is relative, or try entering the complete absolute path to the images folder. If you aren't sure what it is, print the constant __FILE__ to see where the script is running. Link to comment Share on other sites More sharing options...
real_illusions Posted January 9, 2007 Author Share Posted January 9, 2007 thx for thatbut i've tried every path possible, with slashes..without slashes, every combination possible..but with no luck Link to comment Share on other sites More sharing options...
justsomeguy Posted January 9, 2007 Share Posted January 9, 2007 Check __FILE__ like I said to find out the path:echo __FILE__;If you are on a Linux server, the path will be something like this:/home/username/www/images/If it is a Windows server, it will include a drive letter:c:\inetpub\wwwroot\images\Check the environment variables to figure out what the path is that you need to use. Link to comment Share on other sites More sharing options...
real_illusions Posted January 9, 2007 Author Share Posted January 9, 2007 i think i'm getting somewhere now..i'll let you know if i come across any problems while trying to install it into the gallery softwarethanks for your help and patience. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now